shiny.semantic
shiny.semantic copied to clipboard
bugfix: updateSelectInput handle correctly named list as choices
trafficstars
Correct a bug where value is not correctly attributed to the data-value attribute in semantic selectInput when using named list as choices.
Have you read the Contributing Guidelines?
Description
Fix a bug when you use named list as choices list. jsonlite::toJSON badly handle the choices list when it came to R named list. Shiny expect a simple JS array. To do that we just have to unname & unlist the initial choices list to get a value vector.
Definition of Done
- [x] The change is thoroughly documented.
- [x] The CI passes (
R CMD check, linter, unit tests, spelling). - [x] Any generated files have been updated (e.g.
.Rdfiles withroxygen2::roxygenise())
Hi, thank you for your contribution! Two questions:
- Do you happen to have a reproducible example to test the change?
- Do you know if
update_dropdown_input()has some discrepancies too?
Here you'll find a reproducible example. It seems to come from named list including spaces in their names.
library(shiny)
library(shiny.semantic)
ui <- semanticPage(
title = "My page",
shiny.semantic::selectInput(
inputId = "item_picker",
label = "Choose your item",
choices = list()
)
)
server <- function(input, output, session) {
observe({
item_list <- list("my first item" = 1,"my second item" = 2)
shiny.semantic::updateSelectInput(session,
inputId = "item_picker",
label = "Choose your item",
choices = item_list,
selected = 2)
})
}
# Run the application
shinyApp(ui = ui, server = server)