如何使用从列表中选择的所有选项初始化 pickerInput
How to have pickerInput initialize with all choices selected from a list
pickerInput
可以通过将选择列表传递到 selected
框来初始化所有选择的选择,如下所示:
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)
但是,我想使用如下选项列表来执行此操作,但这不起作用。谁能告诉我解决这个问题的方法是什么?
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)
如果您传递向量而不是列表,将选择所有选项:selected = unlist(choice_list)
pickerInput
可以通过将选择列表传递到 selected
框来初始化所有选择的选择,如下所示:
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)
但是,我想使用如下选项列表来执行此操作,但这不起作用。谁能告诉我解决这个问题的方法是什么?
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)
如果您传递向量而不是列表,将选择所有选项:selected = unlist(choice_list)