Reputation: 1326
I have a shiny
app hosted on a server, and part of its functionality is to read local files. I realise there is the very helpful fileIput
function in shiny
package - and I may use it instead - but for now I would like to learn about using file paths. The problem I face follows:
I am using the tm
package, which allows users to read text files either from a directory (using DirSource("filePath")
)or using inidividual files (using 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
}
...
The same function works fine and reads in text files when I am using my shiny
app locally. However, when I upload my app to shinyapp
, and then try to upload a local file, I am unable to read in files.
So, why is it not possible to read in local files by shinyApp when the file path is used? It may be a basic question, but I want to learn.
Thanks in advance.
PS. I would be happy to link to my application if required, it's just that I would like to show my application when it's properly functioning.
Upvotes: 0
Views: 1500
Reputation: 7830
I think you can solve your problem by isolating the part where you source your files : isolate({DirSource("filePath")})
Upvotes: 1