如何从带有selectInput分组选项的下拉框中选定的输入中获取组名称?Building例如,在选择Bankwithin之后Building和Nature在选择Bankwithin之后如何获取Nature?
更新的示例:
# demoing optgroup support in the `choices` arg
shinyApp(
ui = fluidPage(
selectInput("state", "Choose a word:",
list(`Building` = list("Apartment", "Bank", "Hospital"),
`Nature` = list("Bank", "River", "Orange"),
`Color` = list("Blue", "Orange", "Red"))
),
textOutput("result")
),
server = function(input, output) {
output$result <- renderText({
paste("You chose", input$state)
})
}
)
Run Code Online (Sandbox Code Playgroud)
一种方法是存储所有选项及其分组标签的变量,并搜索该选项来自哪个组。但当群体之间存在重叠选择时,这就不起作用了。