【发布时间】:2015-07-16 09:32:20
【问题描述】:
我的一个目录中有一些 .csv 文件,并希望在 ui.R 中读取它们以填充下拉列表的选择参数。但我无法这样做。我已经提到了这些链接,但它们似乎对我没有帮助。 link 1 和 link 2
这是我的 ui.R 代码
library(shiny)
ui <- fluidPage(
#this is where I start with my normal rscript code
#I don't know even if this is allowed but shiny does
#not give me any error in the source code
files <- Sys.glob("/home/ubuntu/r-stockPrediction-master/input/*.csv"),
selection = c(),
for(i in 1:length(files)){
selection[i] = strsplit(strsplit(files[i],"/")[[1]][6],".csv")
},
selectInput("choice","Select your choice",choices=selection),
verbatimTextOutput("text")
)
这是我的 server.R 代码
library(shiny)
server <- function(input,output){
output$text <- renderPrint({
paste("you selected",input$choice,sep=" ")
})
}
当我运行我的服务器时,浏览器页面说
ERROR: object 'selection' not found
我希望我已经提供了所有相关的信息。如果您需要任何进一步的信息,请随时询问。提前谢谢你。
【问题讨论】:
-
您需要将文件调用放在 server.r 中,并让 ui.r 保留应用程序的外观 - 所有数据调用和动态内容(如您所要求的)都应该在服务器中。河。最好通过shiny.rstudio.com 上的一些示例来工作 - 这篇文章最相关shiny.rstudio.com/articles/dynamic-ui.html
-
查看了您提到的链接。但我不想要任何动态的东西。我只想列出我的所有文件并在下拉列表中显示它们@MarkeD