'Shiny App Deployment - Error (cannot change working directory)
I have been trying to deploy a shiny app using rsconnect: deployapp(appname = "myapp"). I get the following message at the command prompt:
Application successfully deployed to https://sitename.shinyapps.io/MyApp/
However, when I launch the app, I get the error message:
ERROR: cannot change working directory
Based on resolution to similar problem on both Stackoverflow and googleforum, I tried using both absolute and relative paths in setwd(). Following are the error messages with both absolute and relative paths to setwd():
Error in setwd("~/Data/Projects/MyApp"): cannot change working directory
Error in setwd("C:/Users/Documents/Data/Projects/MyApp"): cannot change working directory
Any suggestions to resolve the issue would be greatly appreciated. thanks in advance!
Solution 1:[1]
shinyapps.io is a virtualized container service running shiny apps.
- It is most likely linux based. I do not have the time to write up a shiny app to confirm that but like most virtualized containers let us assume it is.
- With 1 being say true. Paths like
C:/do not make sense in the linux world. - Again with 1 in mind the directory structure of
~/Datamight not exist.
Work with relative paths ~/ Also put a checkguard with dir.exists() and dir.create
dirname <- '~/Data/Projects/MyApp'
if (!dir.exists(dirname))dir.create(dirname,recursive=TRUE)
FYI I don't really think your should be doing any setwd() for shinyapps. If the data file is is in ~/Data/Projects/Myapp/somedata.csv you can do a direct read in the app as read.csv('somedata.csv').
The server directory structure is in the form of /srv/shiny-server/MyShinyApp when you upload
Solution 2:[2]
Error in setwd("c:/nonexistent_directory_path") : cannot change working directory
This error message will be generated when a directory does not exist. Verify that directory does in fact exist (ie: check spelling, typos).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 |
