# How to deploy your Renkulab project to an R Shiny application

**URL:** <https://renku.discourse.group/t/how-to-deploy-your-renkulab-project-to-an-r-shiny-application/347>\
**Category:** RenkuLab\
**Created:** [9 June 2021 11:37 UTC](https://renku.discourse.group/t/how-to-deploy-your-renkulab-project-to-an-r-shiny-application/347 "2021-06-09T11:37:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gavin-k-lee](https://yyz2.discourse-cdn.com/free1/user_avatar/renku.discourse.group/gavin-k-lee/32/233_2.png) [@gavin-k-lee](https://renku.discourse.group/u/gavin-k-lee)\
**Post date:** [9 June 2021 11:37 UTC](https://renku.discourse.group/t/how-to-deploy-your-renkulab-project-to-an-r-shiny-application/347/1 "2021-06-09T11:37:05Z")

</div>

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](http://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](https://github.com/rstudio/shiny-examples/blob/master/084-single-file/app.R) or in a _ui.R_+_server.R_ combination, like this [app](https://github.com/rstudio/shiny-examples/tree/master/050-kmeans-example)

A sample set up is at [Renku](https://renkulab.io/projects/lee.gavin.k/renku-to-shiny).

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:

 ![image](https://global.discourse-cdn.com/free1/uploads/renku/original/1X/9dcccb23d18b3f4cd75e9e45a85ae2b26e936aac.png)

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](http://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:  
 ![image](https://global.discourse-cdn.com/free1/uploads/renku/original/1X/c5a075ae04938742a1f42ac51e3bfb82ec080f2b.png)

You will need 3 variables:

- The SHINY\_TOKEN and SHINY\_SECRET can be obtained from your [http://shinyapps.io/](http://shinyapps.io/) account at [shinyapps.io](https://www.shinyapps.io/admin/#/tokens)

 ![tokens](https://global.discourse-cdn.com/free1/uploads/renku/original/1X/a41c5e1ba9068debe61e37cfdceac59d67f12271.png)

- The CI\_PUSH\_TOKEN is generated from the project’s own Personal Access Token page:

 ![image](https://global.discourse-cdn.com/free1/uploads/renku/original/1X/79962ce7f8f00c6ba62e6407918224411fe8bf80.png)

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/](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.

 ![image](https://global.discourse-cdn.com/free1/uploads/renku/original/1X/8270fa453aee1176953fb92e5b388b405768e2a4.png)

1. Navigate to your application name: in this case [gavin-k-lee.shinyapps.io/my-shiny-dashboard](http://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](http://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](http://shinyapps.io) are limited to 5 applications, but this should be sufficient for many users.

Credits: Tao Sun, Rok Roskar
