shiny
shiny copied to clipboard
[Accessibility] `shiny::icons()` are not accessible to screen readers
In the following example (retrieved from example(checkboxGroupInput, package = "shiny")), icons are used for informative purpose. However, the checkbox is not accessible for screen readers until explicit aria-label is used by content creator because this does not provide any icon alt text by default. It would be more desirable and safer if the aria-label is provided by default equal to font name and allow content creators to override that value if necessary.
library(shiny)
ui <- fluidPage(
checkboxGroupInput("icons", "Choose icons:",
choiceNames =
list(icon("calendar"), icon("bed"),
icon("cog"), icon("bug")),
choiceValues =
list("calendar", "bed", "cog", "bug")
),
textOutput("txt")
)
server <- function(input, output, session) {
output$txt <- renderText({
icons <- paste(input$icons, collapse = ", ")
paste("You chose", icons)
})
}
shinyApp(ui, server)
CC @rich-iannone
Related discussion: quarto-ext/fontawesome#8
FWIW you can use fontawesome::fa()
directly (instead of icon()
) which makes it easier to implement accessible icons
@cpsievert I tried dropping fontawesome::fa()
in place of icon()
into
actionButton("go", "Search", icon = fontawesome::fa("magnifying-glass"))
but I see
Error in validateIcon(icon) :
Invalid icon. Use Shiny's 'icon()' function to generate a valid icon