Skip to content

inputID containing a "-" fails to render UI editor #8

Description

@AARON-CLARK

Hi, nice package! I was looking to include your pkg's markdown editor in my shiny app which leverages shiny modules, but it won't render because mdInput() seems to be quite sensitive to hyphens. This is problematic because modules leverage hyphens a ton for namespacing purposes.

Here is a minimal example:

Nothing renders.

library(shiny)
library(shinymarkdown)
ui <- fluidPage(
  mdInput(inputId = "editor-1")
)

server <- function(input, output, session) {}

shinyApp(ui, server)

Here is a shiny modules example:

Note, NS() just concatenates the id arg onto the inputID text string, separated by a hypen. So in this case, it should create an input called "my_namespace-editor".

library(shinymarkdown)
library(shiny)
modUI <- function(id) {
  mdInput(inputId = NS(id, "editor"))
}
modServer <- function(id) {
  server <- function(input, output, session) {
    observe({print(input$editor1_markdown)}) # Print the Markdown
    observe({print(input$editor1_html)}) # Print the HTML
  }
}
ui <- fluidPage(
  modUI ("my_namespace")
)
server <- function(input, output, session) {
  modServer ("my_namespace")
}
shinyApp(ui, server)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions