Managing Shiny App(s)
UpdatingThese 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 app is quite simple. You just overwrite a file and reload the server.
Filesapps are stored in /srv/shiny-server
. This directory corosponds to the root of your website (ie https://shiny.phs.ucdavis.edu/)
Procedure
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
filefiles onto the server.
This is usually done with SFTP FigureMakeoutsurewheretheitdirectoryis supposed to go.A single server can have multiple shiny apps. You will need to look in/srv/shiny-serverto see where it goes. Ifpath you needmoreforinformationthat app exists. If it doesn't you canalsocreatecheckitoutwiththesomethingapache/nginxlike:configssudo
tomkdirsee-Pwhich/srv/shiny-server/myapp1foldermight hold the shiny app you are updating.- Copy
andyouroverwritefiles to theoldpathshinyyouappneed(sudo cp ~/ui.R /srv/shiny-server/myapp1/
) - Make sure the permissions and ownership of all the shiny-server files are correct.
ShinyYouAppscanmustjusthavecopy,onepaste,ofand run the followingfilenames:as is:app.sudo chmod -R 755 /srv/shiny-server sudo chown -R shiny:shiny /srv/shiny-server,bothserver.Randui.R, orindex.Rmddepending on what type of app they have written. You may need to rename the file. - Reload your shiny server to apply changes
sudo systemctl
reloadrestart shiny-server
ThatYou shouldare 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 it.done in R with the following although this can take a while (30+ minutes):
update.packages(ask = FALSE, checkBuilt = TRUE)