Managing Shiny App(s)
These are instructions on how to manage standard shiny apps. For password protection please see New Password Protected Shiny App Deployment (Internal Only)
We assume you have a basic understanding of linux filesystem commands such as sudo
, cp
, ls
, rm -r
, mkdir
. If you need help please reach out
File Structure
All shiny apps are stored in /srv/shiny-server
. This directory corosponds to the root of your website (ie https://shiny.phs.ucdavis.edu/)
Any subdirectories you create will be paths in your url. For instance:
-
/srv/shiny-server/myapp1
will be https://shiny.phs.ucdavis.edu/myapp1 -
/srv/shiny-server/project/myapp1
will be https://shiny.phs.ucdavis.edu/project/myapp1
Inside these folders you must have file(s) with one of these nameing schemes in order to successfully load a webpage.
-
index.html
(you can link to css, js, and other files like with other web servers) -
index.Rmd
-
server.R
andui.R
(Shiny App) -
ui.R
(Shiny App)
If you want to use something else for a homepage (ie. php) please contact IT and we can get that set up for you.
Adding Shiny Apps/Websites
- Get your files onto the server. This is usually done with SFTP
- Make sure the directory path you need for that app exists. If it doesn't you can create it with something like:
sudo mkdir -P /srv/shiny-server/myapp1
- Copy your files to the path you need
sudo cp ~/ui.R /srv/shiny-server/myapp1/
- Make sure the permissions and ownership of all the shiny-server files are correct.
You can just copy, paste, and run the following as is:sudo chmod -R 755 /srv/shiny-server sudo chown -R shiny:shiny /srv/shiny-server
- Reload your shiny server to apply changes
sudo systemctl restart shiny-server
You are now done. Go verify your site is up at the path you expect it to be.
If your app gives you an error please see the Basic Troubleshooting section below
Updating Shiny Apps
The process of updating a shiny app is more or less the same as above.
- Get your files onto the server. This is usually done with SFTP
- Replace your app with the new code
sudo cp ~/ui.R /srv/shiny-server/myapp1/ui.R
- Make sure the permissions and ownership of all the shiny-server files are correct.
You can just copy, paste, and run the following as is:sudo chmod -R 755 /srv/shiny-server sudo chown -R shiny:shiny /srv/shiny-server
- Reload your shiny server to apply changes
sudo systemctl restart shiny-server
If your app gives you an error please see the Basic Troubleshooting section below
Removing Shiny Apps
To remove a shiny app just delete the app and reload
- Delete the app
sudo rm -r /srv/shiny-server/myapp1
- Reload your shiny server to apply changes
sudo systemctl restart shiny-server
Basic Troubleshooting
If your app gives you an error and you are following the instructions above, it is likely because a package your app is using is not installed and you did not use an R package manager like pacman
. In that case just install any packages by running R with:
sudo R
And installing your packages as normal. You might need to do this with any packages loaded with the library()
function
> install.packages(c("shiny", "gdata", "ggmap", "ggplot2"))
You may also want to update all packages to ensure things keep working smoothly. This can be done in R with the following although this can take a while (30+ minutes):
update.packages(ask = FALSE, checkBuilt = TRUE)