how to deploy shiny app that uses local data

2019-01-15 03:22发布

问题:

I'm deploying my shiny app and I don't know how to input my a local dataset. I keep getting Error: object "data" not found. Here is my path to shiny folder.

library(shinyapps)
shinyapps::deployApp('C:\\Users\\Jeremy\\Desktop\\jerm2')

In this directory (jerm2), I have 3 things: ui.R, server.R, and my local dataset, a .csv called proj.csv.

In the server.R file, I set data<-read.csv("proj.csv")

I just don't know how to get Shiny to pick up my datasets.

回答1:

You may want to add a subdirectory in your shiny folder called "Data" and put proj.csv there.

Then, in your server.r put:

data<-read.csv("./Data/proj.csv")

That will make it clear where the data is when the app is deployed to the ShinyApps service.



回答2:

I ran into this same problem. It turned out that I did not have my working directory pointing to my shiny app at the time I used shiny.io to save and deploy my app.

Be sure that if you're loading the data that the code reflects that your shiny app is the working directory.

Otherwise you will get a log error that looks something like this

cannot open compressed file 'C:/Users/Joseph/Documents/data/data.rda', probable reason 'No such file or directory'



回答3:

What I did was to write the csv under a sub folder (i.e. data/) of the shiny app directory and then added data<-read.csv("/Data/proj.csv") in server.r (as indicated in the answer). I didn't put the dot and it works.

Another thing is, when you publish it, don't forget to publish both the shiny app and the file in the shiny app folder.