我有一个shiny
应用,需要相互依赖的下拉菜单。假设某人可以通过四个不同的变量来过滤数据,但是这些变量可以包含彼此的子类别。我希望对较窄变量的选择在进行广泛选择后可以更新。经过一段时间的摸索,我发现shinyWidgets
包中似乎是针对我的问题的定制解决方案。 pickerGroupUI-module
函数似乎完全可以实现我想要的功能。从文档中提取的示例代码如下:
if (interactive()) {
library(shiny)
library(shinyWidgets)
data("mpg", package = "ggplot2")
ui <- fluidPage(
fluidRow(
column(
width = 10, offset = 1,
tags$h3("Filter data with picker group"),
panel(
pickerGroupUI(
id = "my-filters",
params = list(
manufacturer = list(inputId = "manufacturer", title = "Manufacturer:"),
model = list(inputId = "model", title = "Model:"),
trans = list(inputId = "trans", title = "Trans:"),
class = list(inputId = "class", title = "Class:")
)
), status = "primary"
),
dataTableOutput(outputId = "table")
)
)
)
server <- function(input, output, session) {
res_mod <- callModule(
module = pickerGroupServer,
id = "my-filters",
data = mpg,
vars = c("manufacturer", "model", "trans", "class")
)
output$table <- renderDataTable(res_mod())
}
shinyApp(ui, server)
}
这恰好创建了我所需要的,但是我希望能够在每列中选择多个内容。该文档包含对options
的描述,可以将其传递给该函数,并且其中包含一个multiple
自变量,该自变量看来很有希望,但无法正常工作。如果我做类似的事情
params = list(
manufacturer = list(inputId = "manufacturer", title = "Manufacturer:", options = list(multiple = TRUE)),
model = list(inputId = "model", title = "Model:"),
trans = list(inputId = "trans", title = "Trans:"),
class = list(inputId = "class", title = "Class:")
)
同样,如果我将代码放在params
之外,则不会起作用。我通读了文档,并遍历了pickerInput
函数上的示例,但在我需要指出允许多个选择的地方仍然不够。