将本地文件读入服务器上托管的ShinyApp

时间:2014-02-21 13:25:31

标签: r shiny shiny-server

我在服务器上托管了shiny个应用,其部分功能是读取本地文件。我意识到fileIput包中有一个非常有用的shiny函数 - 而我可能会使用它 - 但是现在我想学习使用文件路径。我面临的问题如下:

我正在使用tm包,该包允许用户从目录(使用DirSource("filePath"))或使用个人文件(使用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 个答案:

答案 0 :(得分:1)

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

相关问题