r - 如何仅使用列表名称创建 selectInput?(不显示列表内容)闪亮
问题描述
我有 3 个向量:
colors = c("blue", "red", "green", "yellow", "white", "black")
numbers = c("1", "2", "3", "4")
things = c("phone", "fridge", "computer", "chair", "table", "notebook", "bag", "jacket")
为了将它们全部列在一个列表中,我将它们加入到一个列表中。
list_options = list("colors" = colors, "numbers" = numbers, "things" = things)
我的主要目标是创建一个闪亮的应用程序,它的 SelectInput 仅包含列表名称(“颜色”、“数字”、“事物”)。但是,如果您单击其中一个选项,您将能够获得列表的值以便以后使用它们。
例如,如果您选择“事物”,我想查看向量内的所有变量(电话、冰箱、计算机……)。
有没有办法做到这一点?现在,使用我的代码,该应用程序会显示每个向量的名称及其选项,并为您提供您选择的选项。
这就是我希望在应用程序中看到我的 selectInput 的方式。
但是,正如我所说,我想稍后使用每个向量的内容(在我的示例中,我编写了一个“renderText”)。如果您选择“颜色”,您将看到“蓝色、红色、绿色、黄色……”。
这是我的代码:
colors = c("blue", "red", "green", "yellow", "white", "black")
numbers = c("1", "2", "3", "4")
things = c("phone", "fridge", "computer", "chair", "table", "notebook", "bag", "jacket")
list_options = list("colors" = colors, "numbers" = numbers, "things" = things)
if (interactive()) {
shinyApp(
ui = fluidPage(
selectInput("option", "Options:", list_options),
textOutput("text")
),
server = function(input, output) {
output$text <- renderPrint({
input$option
})
}
)
}
首先十分感谢,
解决方案
我不确定是否理解。是不是你想要的:
shinyApp(
ui = fluidPage(
selectInput("option", "Options:", names(list_options)),
textOutput("text")
),
server = function(input, output) {
output$text <- renderPrint({
list_options[[input$option]]
})
}
)
推荐阅读
- python - 如何找到这些值的最大值
- javascript - 盖茨比“以编程方式从数据创建页面”不起作用
- javascript - axios在返回数据之前返回空数组
- arrays - 当点击/单击视图时,如何从数组中突出显示 UIImageView
- mysql - 如何使用 CTE 和左连接编写查询
- html - 在 div 中移动 div 位置“相对”不起作用
- python - 每次运行时更改日志文件名
- javascript - 未在附加按钮上调用 JavaScript 事件处理程序
- javascript - 我将如何在 Typescript 中实现这种类型(来自 Flow?)
- aws-appsync - 是否可以在运行时 AppSync 中获取在解析器中执行的方法的名称?