繁体   English   中英

如何在Shiny R App中为select.put获取从server.R到ui.R的选项向量

[英]How to get vector of options from server.R to ui.R for selectInput in Shiny R App

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

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

camps应该是一个选择的向量。 此向量取决于在服务器脚本上运行的sql查询并返回阵营的ID:

server.R

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

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

您需要在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")

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM