【问题标题】:How to get vector of options from server.R to ui.R for selectInput in Shiny R App如何在 Shiny R App 中获取从 server.R 到 ui.R 的选项向量以进行 selectInput
【发布时间】:2014-06-05 17:28:49
【问题描述】:

我的 ui.R 文件有一个这样的 selectInput:

selectInput("variable1", "Choose Option:", camps)

camps 应该是一个选项向量。该向量依赖于在服务器脚本上运行并返回营地 ID 的 sql 查询:

服务器.R

df1 <- getCamps("date")
camps <- unique(df1$idCamps)

当我运行应用程序时,ui.R 不知道“营地”是什么,因为它只在 server.R 文件中创建。如何将在 server.R 文件中创建的营地向量传递给 ui.R 文件,以便它们现在成为 selectInput 选择器中可供选择的选项?

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    您需要在 server.R 中创建一个输入对象,并将其作为output 列表的一部分返回给 ui.R:

    在 server.R 中:

    df1 <- getCamps("date")
    camps <- unique(df1$idCamps)
    output$campSelector <- renderUI({
       selectInput("variable1", "Choose Option:", as.list(camps)) 
    })
    

    在ui.R中:

    uiOutput("campSelector")
    

    【讨论】:

    • 我得到 ``` 用户类型的意外字符输出``` 其中 userTypes 是嵌套在 as.list() 每个答案中的字符向量
    【解决方案2】:

    更简单的方法:使用 barPlot() 函数为我工作。 names(dataframe_name[colm]),

    在我的情况下,colmcolm &lt;- as.numeric(input$parameters)

    我从 ui.r 获得 parameters,其中的参数是

    selectInput("parameters", label = "1. Select the variable from the U.F.O. dataset", choices = c("Shape" = 7, "Country" = 4, "AM/PM" = 3, "State" = 6))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 2014-07-13
      • 2019-06-21
      • 2021-03-24
      • 1970-01-01
      相关资源
      最近更新 更多