【问题标题】:Reading a local file into a ShinyApp hosted on server将本地文件读入托管在服务器上的 ShinyApp
【发布时间】:2014-03-23 01:02:34
【问题描述】:

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

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

【问题讨论】:

    标签: r shiny shiny-server


    【解决方案1】:

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

    【讨论】:

    • 感谢您的回复。我刚检查过。我和你写的一样:isolate({ if(input$corpusType=="dir"){ myPath&lt;- input$filePath myCorpus&lt;- Corpus(DirSource(myPath)) myCorpus }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多