Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you pass a vector instead of a list all choices will be selected: selected = unlist(choice_list)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading