R Shiny at IQSS
  • Introduction
  • Getting started
    • Determining your resource requirements
    • Applying for an account
  • Deploying
    • Setup your environment
    • Deploying an example Shiny app
    • Bootstrapping a new Shiny app or migrating a pre-existing Shiny application
    • Developing locally with RStudio
    • Developing locally using Docker
    • Speeding up deployments with Packrat
  • Configuration
    • Setting up a custom domain for your Shiny app
    • Installing additional system-level packages
    • Limiting the number of R Threads
  • Best Practices
    • File storage
    • Using promises
    • Adding routes
  • Troubleshooting
    • Resolving Application Error screen
    • Viewing app logs
    • Viewing resource consumption
    • Configuring Shiny session auto-reconnect
    • Getting support
Powered by GitBook
On this page
  • Starting an app from scratch
  • Integrating a pre-existing R Shiny application
  • Selecting the version of R to use
  • Caveats
  1. Deploying

Bootstrapping a new Shiny app or migrating a pre-existing Shiny application

PreviousDeploying an example Shiny appNextDeveloping locally with RStudio

Last updated 5 years ago

You've deployed the previous example and want to start building an R Shiny application from scratch or migrate a pre-existing app. The easiest way to do either is to clone as a template.

Starting an app from scratch

If you're starting to develop a R Shiny app from scratch -- this process is easy. Login to GitHub, go to , and click the Use this template button.

This will create a new repository based of heroku-docker-r-example-app. You can clone this new repository and use it as a base for your R Shiny application.

You can now begin development using the IDE of your choice.

Integrating a pre-existing R Shiny application

Go to and generate a new repository using Use this template.

Migrating a pre-existing R Shiny application requires a few more steps. The following workflow is our preferred and supported method, but, for the adventurous, all you need is the Dockerfile, heroku.yml and run.R files from the repository.

You must have run.R present in any Shiny project for it to run on Heroku

Clone the newly created repository and add your pre-existing code.

Selecting the version of R to use

The template defaults to using R 3.6.1.

The determines which version of R is used for your code in Heroku.

FROM hmdc/heroku-docker-r:3.6.1-shiny

If you use a diferent version of R, replace 3.6.1 with the desired version of R. At present, we support R 3.5.x to 3.6.1.

If you want to use R 3.5.1, your Dockerfile should look like

FROM hmdc/heroku-docker-r:3.5.1-shiny

Caveats

However, in order for your application to work properly in Heroku, you must ensure that:

  1. You do not use install.packages() anywhere in your code. This will cause R to install packages during application runtime, rather than before the application is launched. There is one exception to this rule when installing libraries from GitHub, explained in #3.

  2. If you're installing custom R packages from GitHub using the devtools library, add an init.R file to your repository and move these installation functions to init.R. All instructions in this file will be executed during the build process, before your application goes live.

If you're familar with and use it, you're in good shape. If not, Packrat is a R library dependency management tool which automatically downloads and builds all libraries required for your application. The R Shiny IQSS toolchain automatically installs Packrat when you deploy your application. No additional steps are necessary.

All your R libraries required with library() exist in .

heroku-docker-r-example-app
heroku-docker-r-example-app
heroku-docker-r-example-app
heroku-docker-r-example-app
Dockerfile
Packrat
CRAN