how to deploy shiny app that uses local data - r

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.

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.

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'

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.

Related

Is that possible to retrieve shiny app source .R files from shinyapp.io?

This is related to corrupted files recovery (RStudio R File Corruption)
Is that possible to see (retrieve) source .R and .Rmd files of the Shiny App that was deployed shinyapp.io?
Lets say - you have just successfully uploaded/deployed your Shiny app to shinyapp.io and then your shiny app code got corrupted on your local machine. Can you recover it from deployed codes?
As mentioned in the comment above, if you deployed your code to shinyapps, you are lucky, all your codes are there!
See this article: https://support.posit.co/hc/en-us/articles/204536588-Downloading-your-application-from-shinyapps-io

Can I download app.R script and data of my shiny app from the shiny website?

I have a shiny app deployed on www.shinyapps.io. The app includes a data set and one script (app.R).
All of a sudden I lost all the access to the data and the script on my local machine. Is there a way that I can download the script app.R and the data from www.shinyapps.io?
Yes, if you login to shinyapps and click on the app name in the dashboard, you should see "Bundle - Download" in the Overview. This will download a tar file which you can uncompress. It should contain app.R plus the other files required to make the app run at shinyapps.

Problem with directory when deploying app on shinyapps

I wrote a golem app and wanted to deploy it on the shinyapp.io. Unfortunately, every time I try to do it the following error comes up (in logs):
Warning in loadSupport(appDir, renv = sharedEnv, globalrenv = NULL) :
Loading R/ subdirectory for Shiny application, but this directory appears to contain an R package. Sourcing files in R/ may cause unexpected behavior.
All files related to my project are stored in one directory, where my golem project was initially created. I also checked and set manually working directory to 'R' folder (where app_server and app_ui are stored). Unfortunately when I deploy my app the mentioned error comes up again. Moreover, every time I close my project in RStudio I save workspace image to '.RData' file (this file is also stored in main directory) - maybe here is a problem (but I also tried to deploy w/o this file and it failes either). I really don't know where the problem lies and what this error means.
Interestingly, regular (single) app.R can be deployed on shinyapps without a problem.
Since Shiny 1.5, if you run a shiny app with a subdir called R/, it will load every function stored in it automatically. You can avoid this setting the autoload option to FALSE, doing:
options(shiny.autoload.r=FALSE)
What I do (I'm not sure whether it is best practice) is setting that up just before calling shiny::runApp(). For intance, I usually have a launch() function in my package, which calls shiny::runApp(). Including the option within this launch() function should fix the issue.
Nonetheless, the message is a warning, not an error, and it is possible that everything is working properly in your shiny app.

Access to Shiny app in another computer within the same network

I've created a Shiny app that runs perfectly when I run it in my computer (I have the "ui.R" and "server.R" files in a directory of my desktop).
But I want to other people in my workplace (also using R and RStudio) can also run it.
I copy the "ui.R" and "server.R" files to a directory in another computer, so anyone with the permissions can access this app.
The problem is that when I move this files to other computer's folder I can't run the app anymore. It gives me the error "No Shiny application exists at the path..."
I set the working directory to this new path where I put the files, so I don't know where the problem is. I have lecture and writing permissions to this folder.
I'm using Windows 7.
A much easier way would be keep server.R and ui.R in one script without copying to a specific area.
shinyApp(ui = ui, server = server)

Uploading csv file to shinyApps.io

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")
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.
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.
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.

Resources