diff --git a/README.md b/README.md index f10453095b993a1a286c68de07f2fe6ca73669df..e2e8ce88769ea9be6a514a0bc0410af0c1206677 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,76 @@ # 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 + +```console +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. + + +```python +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"] +``` + + +___ + +# Initial README File ## Getting started diff --git a/example_proj/Readme.md b/example_proj/Readme.md index a2450acc16139a939290baf377fbae3ed0b75b82..5842d0649643a0515d1c0c97f40b4db1eaf61240 100644 --- a/example_proj/Readme.md +++ b/example_proj/Readme.md @@ -1,3 +1,5 @@ This small Shiny application demonstrates Shiny's automatic UI updates. Move the *Number of bins* slider and notice how the `renderPlot` expression is automatically re-evaluated when its dependant, `input$bins`, changes, causing a histogram with a new number of bins to be rendered. + +Adapt from shiny examples. \ No newline at end of file diff --git a/example_proj/app.R b/example_proj/app.R index 77e36f2faeb65606ebb5b21db8cc32df44fc4930..5c0c4d10e0ad9d5e291c034ef10f38ef029bf6c2 100644 --- a/example_proj/app.R +++ b/example_proj/app.R @@ -1,7 +1,18 @@ +# Name : app.R +# Folder : ~/rshiny-k8s/example_proj +# Date : 05/04/23 +# Aim : Simple example of app developped in RShiny. +# Authors : From Shiny Examples - Modify by Elodie C. et Bryan B. + + +# Load packages ------------------------------------------------------------------- library(shiny) -if (!require(shinythemes)) install.packages("shinythemes"); library(shinythemes) +# Optional librairies - only for test. +# Cran and bioconductor librairies +library(shinythemes) library(affy) +# UI part ------------------------------------------------------------------------- # Define UI for app that draws a histogram ---- ui <- fluidPage( @@ -32,7 +43,7 @@ ui <- fluidPage( ) ) ) - +# Server part ------------------------------------------------------------------------- # Define server logic required to draw a histogram ---- server <- function(input, output) { @@ -57,5 +68,5 @@ server <- function(input, output) { } -# Create Shiny app ---- +# Run Shiny app ---------------------------------------------------------------------- shinyApp(ui = ui, server = server) diff --git a/script_r_to_docker/packages_to_install.csv b/script_r_to_docker/packages_to_install.csv new file mode 100644 index 0000000000000000000000000000000000000000..61c24ce192ea7d9da57d51371b54f54b5332b672 --- /dev/null +++ b/script_r_to_docker/packages_to_install.csv @@ -0,0 +1,33 @@ +Package_name;Deposit_name +shiny;cran +dplyr;cran +shinythemes;cran +DT;cran +rAmCharts;cran +leaflet;cran +colourpicker;cran +shinyBS;cran +shinyWidgets;cran +shinydashboard;cran +shinydashboardPlus;cran +dashboardthemes;cran +shinyjs;cran +pwr;cran +googleVis;cran +ggplot2;cran +simstudy;cran +MASS;cran +plotly;cran +reshape2;cran +bsplus;cran +shinyFeedback;cran +ggpubr;cran +rmarkdown;cran +knitr;cran +ggbeeswarm;cran +gdata;cran +lme4;cran +car;cran +bookdown;cran +htmltools;cran +gridExtra;cran \ No newline at end of file diff --git a/script_r_to_docker/script_install_r_packages.R b/script_r_to_docker/script_install_r_packages.R new file mode 100644 index 0000000000000000000000000000000000000000..8e2eaedbdd885a1c5b4df4da76ecf9a6ceced2dd --- /dev/null +++ b/script_r_to_docker/script_install_r_packages.R @@ -0,0 +1,23 @@ +### Name : script_install_r_packages.R +### Folder : /home/echapeau/Languages/rshiny/in_docker_image/first_app/scripts_R +### Date : 20/03/2023 +### Aim : Install all packages from CRAN and BioConductor, requiered in the Shiny app. + + +#### Load file with the list of packages and the name of the deposit +packages_list <- read.csv(file = "packages_to_install.csv", header = TRUE, sep = ";", stringsAsFactors = FALSE ) + +### CRAN Packages +cran_pkgs <- packages_list[which(packages_list$Deposit_name == "cran"),"Package_name"] +### Bioconductor Packages +bioconductor_pkgs <- packages_list[which(packages_list$Deposit_name == "bioconductor"),"Package_name"] + + +### Install Packages +if (length(cran_pkgs) >= 1) { + install.packages(cran_pkgs, dependencies = NA) +} +if (length(bioconductor_pkgs) >= 1) { + requireNamespace("BiocManager") + BiocManager::install(bioconductor_pkgs, ask = FALSE) +} \ No newline at end of file