将本地文件读取到托管在服务器上的ShinyApp中
问题描述:
我有一个shiny
应用程序托管在服务器上,其部分功能是读取本地文件。我意识到shiny
包中有非常有用的fileIput
函数 - 我可以用它来代替 - 但现在我想了解使用文件路径。我面临的问题如下:将本地文件读取到托管在服务器上的ShinyApp中
我现在用的是tm
包,让用户无论是从目录中读取文本文件(使用DirSource("filePath")
)或使用inidividual文件(使用VectorSource("filePath")
)。
initialCorpus<- reactive({
if(input$confirm==0)
return()
isolate({
if(input$corpusType=="dir"){
myPath<- input$filePath
myCorpus<- Corpus(DirSource(myPath))
myCorpus
}
else if(input$corpusType=="vector"){
myPath<- input$filePath
myFile<- scan(file=myPath,what="character",n=-1, sep="\n")
myCorpus<- Corpus(VectorSource(myFile))
myCorpus
}
...
同样的功能工作正常,当我使用我的本地应用程序shiny
在文本文件中读取。但是,当我上传我的应用程序到shinyapp
,然后尝试上传本地文件时,我无法读取文件。
那么,为什么在使用文件路径时不能通过shinyApp读取本地文件?这可能是一个基本问题,但我想学习。
在此先感谢。
PS。如果需要,我会很乐意链接到我的应用程序,只是我想在应用程序正常运行时显示我的应用程序。
答
我想你可以通过隔离在您源文件的部分解决您的问题:isolate({DirSource("filePath")})
感谢您的答复。我刚刚检查过。我有和你写的一样的方法:'{(输入$ corpusType ==“dir”){myPath