How to deploy your Renkulab project to an R Shiny application

Renkulab has always supported R and RStudio as part of its interactive sessions. The canonical way of sharing your data science project to the world is of course R Shiny. In this post we show you how you can deploy R Shiny applications directly from your Renkulab project.

Pre-requisites:

  • we will be using shinyapps.io as a hosting service so make an account there before proceeding.
  • your RenkuLab project is assumed to be in R, hopefully a recent version of Renku and R
  • you have a sample application, either in a single file like this app or in a ui.R+server.R combination, like this app

A sample set up is at Renku.

  1. Add your application files to your RenkuLab repository.

  2. Touch up your application in RStudio. In order to view the application in the interactive session, you will need to add the following line in your Dockerfile:

RUN /rocker_scripts/install_shiny_server.sh
Once that is installed, you should be able to view an application using the “Run App” button:

  1. Once you are happy with your changes, push your changes to git and exit the interactive session.

  2. Alter the .gitlab-ci.yml file to include the pattern as shown in the sample project. The section containing the SHINY variables defines the resulting app URL. In this case, the shinyapps account is gavin-k-lee and has the application name my-shiny-dashboard. The shiny server is the free shinyapps.io site - this can be configured to be RSConnect or another (paid) hosting solution if you have one.

In this case:
SHINY_USER: "gavin-k-lee"
SHINY_SERVER: "shinyapps.io"
SHINY_APPNAME: "my-shiny-dashboard"

  • The image_build section should be untouched as this is the tag from which interactive sessions are built.
  • The shiny_image_build builds another (identical) image which is necessary since the proceeding step does not use the image_build image properly.
  • The update_dashboard section updates the R Shiny dashboard.
  1. Add the right credentials: navigate to the Settings → CI/CD section in the Renkulab GitLab:

You will need 3 variables:

  • The CI_PUSH_TOKEN is generated from the project’s own Personal Access Token page:

Create this token and add it to the variables as in the previous instruction. You should allow api, read_api, read_repository and write_repository.

  1. Check that with each commit to your repository (either from http://renkulab.io/ sessions or locally), your CI/CD pipeline succeeds. This may take a while, especially for the first time or if you have many changes.

  1. Navigate to your application name: in this case gavin-k-lee.shinyapps.io/my-shiny-dashboard.

  2. The magic: now any changes to your application which are pushed to your Renkulab project will be automatically pushed to shinyapps.io! It will take a minute or two to be updated, but you can check the progress of the pipeline by looking at the CI/CD section in Renkulab’s GitLab.

Happy dashboarding! Note that free accounts on shinyapps.io are limited to 5 applications, but this should be sufficient for many users.

Credits: Tao Sun, Rok Roskar

7 Likes