rstudio / shiny

Easy interactive web applications with R
https://shiny.posit.co/
Other
5.37k stars 1.87k forks source link

selectInput() helper selectOptions() always escapes choice names #2603

Open nteetor opened 5 years ago

nteetor commented 5 years ago

I was hoping to include some non-breaking spaces in a select input choice. But, I discovered even when using HTML() the choice names are always escaped. This happens in shiny:::selectOptions(). Is there any chance selectOptions() could be updated to check for values marked with HTML() and not escape those values? Is so, I can put together a PR.

stla commented 4 years ago

You can use the render option of selectize:

render <- "
{
  option: function(data, escape){return '<div class=\"option\">'+data.label+'</div>';},
  item: function(data, escape){return '<div class=\"item\">'+data.label+'</div>';}
}"

ui <- fluidPage(
  selectizeInput(
    "age", "Age category", 
    choices = c(
      "&le; 6 months" = 1,
      "6 months - 17 years" = 2,
      "&ge; 18 years" = 3
    ),
    options = list(
      render = I(render)
    )
  )
)

server <- function(input, output){}

shinyApp(ui, server)