'How to have pickerInput initialize with all choices selected from a list
pickerInput can be made to initialize with all choices selected by passing the choice list into the selected box as follows:
library(shiny)
choice_list <- c("Tom", "Hank", "Kelly")
ui <- fluidPage(
pickerInput(inputId = "grp_sel",
label = "Select Groups",
choices = choice_list,
selected = choice_list,
multiple = T)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
However, I would like to do this with a list of choices as follows but this is not working. Can anyone tell me what a solution is to this?
choice_list <- list("Group A" = c("Tom", "Jenny", "Kim"),
"Group B" = c("Hank", "James", "Kelly"))
ui <- fluidPage(
pickerInput(inputId = "grp_sel",
label = "Select Groups",
choices = choice_list,
selected = choice_list,
multiple = T)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
Solution 1:[1]
If you pass a vector instead of a list all choices will be selected: selected = unlist(choice_list)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ekolima |
