我保存了用户定义文件夹的路径shinyDirChoose
。现在我想从该用户的文件夹上传文件,但我不知道该怎么做。
1)全部在服务器端?
2)将文件路径提供给fileInput
不知何故?
这就是我构建应上传的三个文件的文件路径的方法。
### ui end, to browse to desired folder
ui = fluidPage(shinyDirButton('directory', 'Folder select', 'Please select a folder'))
### extracting the folder path
server = function(input, output, session) {
volumes <- getVolumes()
shinyDirChoose(input, 'directory', roots=volumes, session=session)
path1 <- reactive({
return(print(parseDirPath(volumes, input$directory)))
})
### constructing the 3 file paths
datpat <- renderText({
req(nchar(path1())>0)
datpat <- paste0(path1(),"/data.csv")
})
vispat <- renderText({
req(nchar(path1())>0)
vispat <- paste0(path1(),"/visit.csv")
})
statpat <- renderText({
req(nchar(path1())>0)
statpat <- paste0(path1(),"/statvisit.csv")
})
那么现在我有了这些路径,但是如何使用它们将相关内容上传到服务器呢?一个简单的read.csv
不幸的是并不能解决问题。
编辑-但还没有...
在 @SBista 提供的巨大帮助下进一步工作,我想我正在接近我的目标,但请参阅下面的代码......
volumes <- getVolumes()
shinyDirChoose(input, 'directory', roots=volumes, session=session)
path1 <- reactive({
return(print(parseDirPath(volumes, input$directory)))
})
observe({
if(!is.null(path1)){
### vis1
vis1 <- reactive({
datpat <- paste0(path1(),"/visit.csv")
vis <- read.csv(datpat, header = input$header, sep = input$sep, quote = input$quote,
stringsAsFactors = FALSE)
vis
})
### dataruw1
dataruw1 <- reactive({
datpat <- paste0(path1(),"/data.csv")
dataruw <- read.csv(datpat, header = input$header, sep = input$sep, quote = input$quote,
stringsAsFactors = FALSE)
dataruw
})
}
})
很遗憾,dataruw1
and vis1
似乎没有生成,因为在尝试使用实际数据时出现“无法找到函数”错误dataruw1()
and vis1()
。我缺少什么?任何想法?预先非常感谢!