2014-02-21 69 views
0

我有一个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。如果需要,我会很乐意链接到我的应用程序,只是我想在应用程序正常运行时显示我的应用程序。

回答

1

我想你可以通过隔离在您源文件的部分解决您的问题:isolate({DirSource("filePath")})

+0

感谢您的答复。我刚刚检查过。我有和你写的一样的方法:'{(输入$ corpusType ==“dir”){myPath < - 输入$ filePath myCorpus < - 语料库(DirSource(myPath))myCorpus}' –

相关问题