Skip to content
Snippets Groups Projects
Bryan  BRANCOTTE's avatar
Bryan BRANCOTTE authored
Revert "build both dockerfile"

See merge request hub/rshiny-k8s!2
a32eddbe
History

rshiny-k8s

Aim of the project

Help hub members to deploy correctly and easily an Web application, initially developed in RShiny, under Kubernetes.

Workflow

This workflow described all steps to follow in order to deploy your app under kubernetes available at Institut Pasteur - Paris.

  1. Develop your shiny app
  2. Create a docker image
  3. Init the deployement under gitlab
  4. Configure your deployement under kubernetes.

Step 1. Develop your shiny app

Create your shiny app by following the basic best practices like using multiple files (ui.R, server.R and global.R) and save files on gitlab project.

Your are free to develop your app as you want. The only constraint is to list the requiered packages.

List all the packages needed by your application in an dedicated file - named "packages_to_install.csv" respecting the following structure : ---> Name of the package;Name of the repository where the package will be found

Package_name;Deposit_name
shiny;cran
dplyr;cran
affy;bioconductor
...

Be carefull not to put any space character at the end of word.

This file will be used by the dockerfile in order to install all packages on the shiny server.

Step 2. Create a docker image

The purpose of the docker image is to create a proper environment where your Shiny application will be hosted. Your application will be containerized.

This container will contain:

  • an Ubuntu Linux system with R installed
  • a shiny server (not the professional version)
  • your app

All these requirements are listed in a dedicated file named "Dockefile".

In this file, you only need to indicate the folder name of your application. Replace "MyAppName" with the correct name.

FROM rocker/shiny:latest
USER root
# delete previous exemples on shiny-server
RUN rm -rf /srv/shiny-server/*
# change permission for user shiny
RUN sudo chown -R shiny:shiny /usr/local/lib/R/etc/
## Install R packages from CRAN or bioconductor
COPY ./script_r_to_docker/script_install_r_packages.R .
COPY ./script_r_to_docker/packages_to_install.csv .
RUN Rscript script_install_r_packages.R

WORKDIR /srv/shiny-server/

# copy the app directory into the image
COPY ./MyAppName/. /srv/shiny-server/MyAppName/

USER shiny
CMD ["/usr/bin/shiny-server"]

Troubleshooting, dev cheat sheet

Build the image, and run it

docker build . -t rshiny-k8s-test
docker run -it -p 3838:3838 rshiny-k8s-test

To locally run the server

docker build . -t rshiny-k8s-test
docker run --rm -ti -v $(pwd)/example_proj:/srv/shiny-server --user shiny -p 3838:3838 rocker/shiny
docker run --rm -ti -v $(pwd)/example_proj:/srv/shiny-server -p 3838:3838 rocker/shiny