R shinyapp从复选框中选择预存储的数据集 ui

R shinyapp从复选框中选择预存储的数据集 ui,r,visualization,shiny,shiny-server,R,Visualization,Shiny,Shiny Server,在shiny中执行此操作的典型方法是使用switch(),这意味着您不需要在输入中指定数据集,您可以在服务器中完成所有操作。在你的背景下: ui <- fluidPage( checkboxGroupInput("data", "Select data:", c("Iris" = "iris", "Cars" = "mtcars")), plotOutput("myPlot")

在shiny中执行此操作的典型方法是使用
switch()
,这意味着您不需要在输入中指定数据集,您可以在服务器中完成所有操作。在你的背景下:

ui <- fluidPage(
    checkboxGroupInput("data", "Select data:",
                       c("Iris" = "iris",
                         "Cars" = "mtcars")),
    plotOutput("myPlot")
  )

  server <- function(input, output) {
    output$myPlot <- renderPlot({
      plot(Sepal.Width ~ Sepal.Length, data = input$data)
    })
  }

  shinyApp(ui, server)
库(闪亮)

ui您的
输入$data
将返回字符向量
“iris”
,而不是数据集
iris
。在绘图功能中,更改为此
data=data(输入$data)
,它将加载指定的数据set@waterling谢谢你的快速回复。是的,我也注意到了。不幸的是,你的建议不起作用。我得到了相同的错误:“无效的'character'hm ok类型的'envir'参数。”。尝试
get(输入$data)
。这对我很有用<代码>输出$myPlot
library(shiny)
ui <- fluidPage(
  checkboxGroupInput("data", "Select data:",
                     c("Iris" = "iris",
                       "Cars" = "mtcars")),
  plotOutput("myPlot")
)

server <- function(input, output) {
  dat <- reactive({
    switch()
  })
  output$myPlot <- renderPlot({
    dat <- switch(input$data, 
                  "iris" = iris,
                  "mtcars" = mtcars)
    plot(Sepal.Width ~ Sepal.Length, data = get(input$data))
  })
}

shinyApp(ui, server)