Helper scripts
configure_Rprofile.sh
The bash script configure_Rprofile.sh
contains all instructions
to configure the mirror site in order to download R packages.
By default, we choose the official CRAN r-project.
1 #!/bin/bash
2 set -e
3
4 R_HOME=${R_HOME:-"/usr/local/lib/R"}
5 DEFAULT_MIRRORS='"https://cran.r-project.org"'
6
7 cat <<EOF >"${R_HOME}/etc/Rprofile.site"
8 options(
9 repos = c(${MIRRORS:-${DEFAULT_MIRRORS}}),
10 download.file.method = 'libcurl'
11 )
12 EOF
13
14 echo "Here is the configured Rprofile"
15
16 cat ${R_HOME}/etc/Rprofile.site
install_r_cran.sh
You can see below the content of bash script who permits to install and configure the chosen version of R in the container according to the CRAN installation documentation
1 #!/bin/bash
2 set -e
3
4 R_VERSION=${1:-${R_VERSION:-latest}}
5
6 cd /tmp
7
8 if [ ! -f "R-${R_VERSION}.tar.gz" ]; then
9 echo "/tmp/R-${R_VERSION}.tar.gz is missing, downloading it"
10 if [ "$R_VERSION" = "latest" ]; then
11 curl -O https://cran.r-project.org/src/base/R-latest.tar.gz
12 else
13 curl -O https://cran.r-project.org/src/base/R-${R_VERSION::1}/R-${R_VERSION}.tar.gz
14 fi
15 fi
16 tar -xzvf R-${R_VERSION}.tar.gz
17
18 # go in uncompressed dir, when using R_VERSION="R-latest",
19 # the dir is not R-latest, but the one with the version
20 cd R-*/
21 # Configure the sources, check dependencies
22 ./configure \
23 --enable-R-shlib \
24 --enable-memory-profiling \
25 --with-blas \
26 --with-lapack \
27 --with-x=yes \
28 --with-cairo=yes \
29 --enable-java=no
30
31 make
32 make install
33
34 echo "Install completed, testing R"
35
36 R -q -e "sessionInfo()" || exit 1
37
38 echo "R found in path, good to go!"
39
40 make clean
41 rm /tmp/R-${R_VERSION}.tar.gz
Go back to Dockerfile.r - 40-49 : Installation of R
install_r_packages.R
You can see below the content of R script who permits to install several mandatory packages. This script install R packages and dependencies by using the pak package . More details here
1 #!/usr/bin/env Rscript
2 ### Name : install_r_packages.R
3 ### Folder : ~/scripts
4 ### Date : 17/04/2023
5 ### Aim : Install all packages from CRAN, BioConductor or github, requiered in the Shiny app.
6
7 ### Install pak packages first
8 # Specify your packages
9 my_packages <- c("pak","pkgcache","pkgdepends","pillar")
10 # Extract not installed packages
11 not_installed <- my_packages[!(my_packages %in% installed.packages()[ , "Package"])]
12 # Check if packages are yet installed
13 if(length(not_installed)){
14 print("packages needed to install in the basic image ...")
15 install.packages(not_installed, dependencies= NA)
16 print("...done")
17 }else{
18 print("packages previously installed in the basic image")
19 }
20
21 #### Load file with the list of packages
22 packages_list <- read.csv(file = "/opt/scripts/packages_to_install.csv", header = TRUE, sep = ";", stringsAsFactors = FALSE)
23 print("Installation for other packages needed : ")
24 print(paste(packages_list$Package_name, sep = "",collapse = ","))
25
26 ### Install packages with dependencies with pak packages
27 if (length(packages_list$Package_name)>=5){
28 print ("at least 5 packages to install")
29 for(i in 1:length(packages_list$Package_name) ) {
30 print(packages_list$Package_name[i])
31 pak::pkg_install(pkg=packages_list$Package_name[i])
32 }
33 }else {
34 print("packages to install : ", packages_list$Package_name)
35 + pak::pkg_install(pkg=packages_list$Package_name)
36 }
37 # clean the cache of pak
38 pak::cache_clean()
Go back to Dockerfile.r - Lines 51-57: Installation of R packages
install_shiny_server.sh
Below, you found the contents of bash script /opt/scripts/install_shiny_server.sh
.
1#!/bin/bash
2set -e
3
4SHINY_SERVER_VERSION=${1:-${SHINY_SERVER_VERSION:-latest}}
5
6
7if [ "$SHINY_SERVER_VERSION" = "latest" ]; then
8 SHINY_SERVER_VERSION=$(wget -qO- https://download3.rstudio.org/ubuntu-18.04/x86_64/VERSION)
9fi
10
11wget --no-verbose "https://download3.rstudio.org/ubuntu-18.04/x86_64/shiny-server-${SHINY_SERVER_VERSION}-amd64.deb" -O /tmp/shiny.deb
12apt install /tmp/shiny.deb
13rm /tmp/shiny.deb
This script permits, according to the number of version mentionned in the Dockefile, :
the download of deb package corresponding to shiny-server by
wget
instruction,this installation by
apt install
and the delete of file previously downloaded
Go back to Dockerfile.python - Lines 46-49 : Installation Shiny Server
Go back to Dockerfile.r - Line 58 : Installation Shiny Server