Zhe*_*ang 5 r shiny selectinput
如何从带有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)
一种方法是存储所有选项及其分组标签的变量,并搜索该选项来自哪个组。但当群体之间存在重叠选择时,这就不起作用了。
小智 0
您可以为每个输入指定一个值,而不是直接使用它们的名称,如下所示:
shinyApp(
ui = fluidPage(
selectInput("state", "Choose a word:",
list(`Building` = list("Apartment"="ap", "Bank"="bk", "Hospital"="hp"),
`Nature` = list("Bank"="bk1", "River"="rv", "Orange"="or"),
`Color` = list("Blue"="bl", "Orange"="or1", "Red"="rd"))
),
textOutput("result")
),
server = function(input, output) {
output$result <- renderText({
paste("You chose", input$state)
})
}
)
Run Code Online (Sandbox Code Playgroud)