py404 / r-shiny-docker-kubernetes

Containerize R Shiny apps with Docker 🐳 and deploy to Kubernetes ☸

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🚀 Containerize R Shiny apps with Docker 🐳 and deploy to Kubernetes ☸️ Cluster

This project repository will help you to set up your R Shiny apps and:

  • Containerize using Docker 🐳
  • Deploy to Kubernetes ☸️ cluster using manifests
  • Deploy to Kubernetes ☸️ cluster using Helm charts
  • To-do: Use ShinyProxy for authentication and deploy ShinyProxy to Kubernetes ☸️ cluster
  • To-do: Use Nginx HTTP authentication and deploy to Kubernetes ☸️ cluster

I used Windows 10 as my local machine with minikube setup (Kubernetes) for this project. However, all the tools that I've listed are available on macOS and Linux distros.

Repository branches:

master branch ➡️ Docker files

kubernetes ➡️ Docker files ➕ Kubernetes deployment with manifests

helm ➡️ Docker files ➕ Kubernetes deployment with Helm chart

Notes:

"master" branch has files for dockerizing shiny app with shiny server

"kubernetes" branch has files for dockerizing shiny app and deploying to Kubernetes cluster using manifests

"helm" branch has files for dockerizing shiny app and deploying to Kubernetes cluster with Helm charts

1. 📦 Software requirements

Please make sure that you have the following software setup on your computer.

  1. ✨ Git - https://git-scm.com/downloads

  2. 🚀 WSL 2 (mandatory for Windows) installation steps / or feel free to use other virtualization technologies

  3. 🐳 Docker - https://hub.docker.com/editions/community/docker-ce-desktop-windows/

  4. 💻 Other docker UI tools (not mandatory) - docker desktop UI is good enough to view all your containers and images, I personally like Portainer and Dockstation because of their custom features that are not there in the default docker desktop GUI application.

2. 🗂️ Project setup and details

Clone the repository from - https://github.com/py404/r-shiny-docker-kubernetes locally before going to next sections.

For docker deployment, stay in the master branch and proceed to next steps.

2.1 Project structure

Project files and folders required are:

📦r-shiny-docker-kubernetes
 ┣ 📂app
 ┃ ┗ 📜app.R
 ┣ 📂Docker
 ┃ ┣ 📂nginx
 ┃ ┃ ┣ 📜nginx.conf
 ┃ ┃ ┗ 📜nginx.Dockerfile
 ┃ ┣ 📂shiny
 ┃ ┃ ┣ 📜index.html
 ┃ ┃ ┗ 📜shiny.Dockerfile
 ┃ ┣ 📜.dockerignore
 ┃ ┗ 📜docker-compose.yml
 ┣ 📜.gitignore
 ┗ 📜README.md

🗂️ app folder - contains app.R which has a simple shiny dashboard bins app.

To containerize your own shiny apps, copy your project files to app folder and proceed to next steps for docker deployment.

🗂️ Docker folder - contains docker files for shiny server and nginx.

3. 🐳 Docker deployment

  1. cd (change directory) to Docker folder

  2. Run docker compose command

    docker-compose up -d --build
    

    This command will create 2 containers:

    (a) a Shiny server container
    (b) an nginx container
    

Nginx container acts as a proxy server for connecting to the shiny server.

docker-compose

Docker compose commands breakdown:

  • The following only builds the images, does not start the containers:

    docker-compose build
  • The following builds the images if the images do not exist and starts the containers:

    docker-compose up
  • If you add the --build option, it is forced to build the images even when not needed:

    docker-compose up --build

Navigate to http://localhost:3838 in your browser

shiny-server

About

Containerize R Shiny apps with Docker 🐳 and deploy to Kubernetes ☸


Languages

Language:HTML 49.2%Language:Dockerfile 29.8%Language:R 20.9%