在一个闪亮的应用程序中,我有一个varSelectInput小部件,用于从虹膜数据集中选择变量。有没有一种方法可以将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()
})
}
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句