Skip to content

Passing HTML-escaped choices doesn't work consistently #747

@brianwdavis

Description

@brianwdavis

I have a form that has choices that include an ampersand, &. Even when I try to wrap the label in HTML(), it sometimes shows as &. Here's some screenshots and code that shows the bug.

While testing this, I also noticed related additional unexpected behavior: the selection chip is being rendered from the label = argument of prepare_slim_choices(), and not the html = argument. You can test this by replacing label = name with label = seq_along(name) and the dropdown will show "Apples & Bananas" but the chip will show "1".

With no escaping
Image

Escaping partially works
Image

None of the selection chips work
Image

library(shiny)
library(shinyWidgets)

dat = data.frame(name = "Apples & Bananas", value = "apples_bananas")

ui <- fluidPage(
  slimSelectInput(
    "input1", 
    label = "Label only (wrong in dropdown and chip)",
    choices = prepare_slim_choices(
      dat,
      label = name, 
      value = value
    ),
    multiple = T
  ),
  
  slimSelectInput(
    "input2", 
    label = "With HTML (correct in dropdown, wrong in chip)",
    choices = prepare_slim_choices(
      dat,
      label = name, 
      value = value, 
      html = purrr::map(name, HTML)
    ),
    multiple = T
  ),
  
  slimSelectInput(
    "input3", 
    label = "With HTML and marking label as HTML (correct in dropdown, wrong in chip)",
    choices = prepare_slim_choices(
      dat,
      label = purrr::map(name, HTML), 
      value = value, 
      html = purrr::map(name, HTML)
    ),
    multiple = T
  ),
)

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

shinyApp(ui, server)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions