Skip to main content

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, mv, 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:

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 and ui.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

  1. Get your files onto the server. This is usually done with SFTP
  2. 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
    
  3. Copy your files to the path you need
    sudo cp ~/ui.R /srv/shiny-server/myapp1/
    
  4. 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
    
  5. 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.

  1. Get your files onto the server. This is usually done with SFTP
  2. Replace your app with the new code
    sudo cp ~/ui.R /srv/shiny-server/myapp1/ui.R
    
  3. 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
    
  4. 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

  1. Delete the app
    sudo rm -r /srv/shiny-server/myapp1
    
  2. Reload your shiny server to apply changes
    sudo systemctl restart shiny-server
    

Basic Troubleshooting

Missing Packages/Random Errors

If your app loads but gives you anrandom errorerrors andor youjust aredoesnt followingwork the instructions above,properly, it is likely because a package your app is using a package that 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)

Index of /path/ Screen

If you get a Index of /path/ page when you load your app, and you were expecting a shiny app/webpage, it is likely because you did not name your app correctly.

Sometimes this page is what you want, but if it is not, rename your app to one of the following:

  • index.html
  • index.Rmd
  • server.R and ui.R (Shiny App)
  • ui.R (Shiny App)

If it isn't the shiny server will not find and load your app

Unable To Write/Save Files

If your app tries to write to a file but it isnt writing properly. Make sure permissions are correct. If you have incorrect permissions your app will not be allowed to write to the directory.

To fix this, just copy and run the lines below

sudo chmod -R 755 /srv/shiny-server
sudo chown -R shiny:shiny /srv/shiny-server

New Shiny App Is Not Showing Up

This is likely because you didn't reload the server after updating your app files. Run the following to update it.

sudo systemctl restart shiny-server