r - R Shiny:varSelectInput 仅来自数据帧的数字变量
问题描述
在一个闪亮的应用程序中,我有一个 varSelectInput 小部件来从 iris 数据集中选择变量。有没有一种方法可以将 varSelectInput 中的变量限制为仅限数字变量。我尝试使用 is.numeric(iris),但没有成功。谢谢。
我的代码:
library(shiny)
library(ggplot2)
# single selection
shinyApp(
ui = fluidPage(
varSelectInput("variable", "Variable:", is.numeric(iris),
selected = NULL),
plotOutput("data")
),
server = function(input, output) {
output$data <- renderPlot({
ggplot(iris, aes(!!input$variable)) + geom_histogram()
})
}
)
解决方案
您可以尝试Filter
:
library(shiny)
library(ggplot2)
shinyApp(
ui = fluidPage(
varSelectInput("variable", "Variable:", Filter(is.numeric, iris),
selected = NULL),
plotOutput("data")
),
server = function(input, output) {
output$data <- renderPlot({
ggplot(iris, aes(.data[[input$variable]])) + geom_histogram()
})
}
)
推荐阅读
- java - 如何读取 string.xml 文件中的 .txt?
- regex - sed - 从 pattern2 之前的 pattern1 删除到 pattern2 之后的 pattern3
- vue.js - 使用 vue 组件的构建版本时组件闪烁和消失(服务时没有问题)
- wordpress - 如何在 Storefront 的顶部栏和页脚区域添加自定义框架
- progressive-web-apps - 使用 @nuxt/pwa 清除缓存后,渐进式 Web 应用程序不起作用
- c# - SqlException 出现时间过长
- node.js - npm SSL 错误:使用 sha512 时完整性校验和失败
- node.js - 如何在 ReactJS 中更新和预填充表单
- sql - 如何修复更新查询中的语法错误(缺少运算符)
- python - 为什么内联交换返回意外结果?