r - 使用 selectinput 从数据框中提取列值
问题描述
例如,我有一个数据框 mtcars,我只想根据 selectinput 中的变量选项提取列值。
示例代码:
shinyApp(
ui = fluidPage(
varSelectInput("variable", "Variable:", mtcars),
verbatimTextOutput('data')
),
server = function(input, output) {
output$data <- renderText({
mtcars$input$variable
})
}
)
例如:mtcars$mpg
I want only to extract the mpg vector values: 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7 15.0 21.4
解决方案
试试这个
output$data <- renderText({
paste(mtcars[[as.name(input$variable)]])
})
推荐阅读
- javascript - 量角器,如果其他类具有相同的类名,如何获取元素
- android - 图层列表 - 边距底部
- python-2.x - 当我从用户那里获取输入并想要转换该输入时,系统错误
- java - 为什么 Java 中的 contains() 方法不能按预期工作?
- javascript - ReferenceError:未定义 twitterFetcher
- reporting-services - 无法加载文件或程序集 | 报表生成器 3.0
- php - jQuery Ajax 获取 json 返回结果
- java - java中的xslt转换期间属性名称使用了非法值
- hazelcast - Hazelcast localKeySet
- asp.net - 通过 post 正确接收嵌套对象