Reputation: 309
My app runs fine locally and I am able to successfully deploy my app to the shinyapps.io server, but I get the following error message when I try and load the app in my browser using the shinyapps URL: "Error object 'data' not found.' I think this is because the 'data' variable reads from a csv file on my local directory. Is there a way I can upload this csv file to the shinyapps server? I've tried looking this up but I've found nothing.
Here's the code I am using to read in the files. I'm getting the file from the same working directory as my server.R and ui.R. Thanks
server.R
library(shiny)
college = read.csv("college.csv")
ui.R (I added to this to see if it fixes the problem, but it doesn't)
library(shiny)
college = read.csv("college.csv")
Upvotes: 13
Views: 7145
Reputation: 701
I know it's too late but I believe creating a folder named www in your directory and placing the csv there should solve the problem.
Upvotes: 0
Reputation: 33
Currently I was facing a similar trouble.
Reading here and there, I realized that you can create a script called global.R
in the same dir with ui.R
and server.R
.
On this file (global.R) you can load libraries and, in this case, objects previously saved on a dir, for example, called data.
I created the object and the saved it with saveRDS(df, "./data/df.RDS")
. Then loaded it from the data dir with something like
df <- readRDS("data/df.RDS")
on the global.R That works for me.
Upvotes: 1
Reputation: 6913
Best practice would be to place your data in a folder, say ~/<application name>/data
and then call your data from your server.R
treating your application's directory (/<application name>/
) as the current working directory.
e.g. I save my files as RDS objects in ~/ImputationApp/data/
and then read them in with:
foo.rds <- readRDS("data/foo.rds")
Even though what you describe should run, double check your filepaths for the datafiles you are trying to load and any stray setwd()
commands that could be mucking up the works. A common misstep is to put the fully qualified path to your data on your machine in your server.R
.
Upvotes: 0