10
votes

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")
2
Are you sure your csv file is located in the app directory? Before uploading the app I mean. - rdatasculptor
Yes it's in the app folder. I'm really perplexed as to why it doesn't upload to the server. - Kamal
I have no problem loading csv file in shiny. Could you post your code where you are loading csv file? - Jonas
Could it be that you do something wrong with how you define the path to the csv? - rdatasculptor
I've gone ahead and added the code to show how I'm reading in the csv file. It's in the same directory as my shiny files, but it doesn't get uploaded to the shinyapps server for some reason. - Kamal

2 Answers

0
votes

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.

0
votes

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.