我正在构建一个利用selectInput()中的嵌套列表的Shiny应用程序。是否可以增加选择特定子列表中所有项目的能力?
R版本3.5.3 闪亮的版本1.2.0
下面的是一个非常基本的闪亮应用程序,用于说明问题。在我的实际用例中,子列表长于4个项目,因此选择每个元素会很费时。
library(shiny)
east <- list("DAL" = "Dallas Cowboys",
"NYG" = "New York Giants",
"PHI" = "Philadelphia Eagles",
"WAS" = "Washington Redskins")
north <- list("CHI" = "Chicago Bears",
"DET" = "Detroit Lions",
"GB" = "Green Bay Packers",
"MIN" = "Minnesota Vikings")
south <- list("ATL" = "Atlanta Falcons",
"CAR" = "Carolina Panthers",
"NO" = "New Orleans Saints",
"TB" = "Tampa Bay Buccaneers")
west <- list("AZ" = "Arizona Cardinals",
"LAR" = "Los Angeles Rams",
"SF" = "San Francisco 49ers",
"LAC" = "Los Angeles Chargers")
ui <- fluidPage(
selectInput(inputId = "nfc",
choices = list("east" = east,
"north" = north,
"south" = south,
"west" = west),
label = "teams",
multiple = TRUE),
textOutput("selected")
)
server <- function(input, output, session) {
output$selected <- renderText({paste(input$nfc, collapse = ", ")})
}
shinyApp(ui, server)
我希望用户能够选择NFC East中的所有球队,例如,通过单击下拉菜单中的“ east”,或在列表中添加一个选项来选择所有nfc east团队。
注意:向"all" = c("Dallas Cowboys", "New York Giants", "Washington Redskins", "Philadelphia Eagles")
添加第五个选项east <- list(..)
并不理想,因为我希望用户能够随后取消选择球队(即选择所有nfc东部球队,然后排除牛仔队) )。