Skip to content

Instantly share code, notes, and snippets.

@ghBack
Forked from IdoBar/install_shiny_server.bash
Created September 18, 2018 01:30
Show Gist options
  • Save ghBack/e6c0b0b706acac2f3a7d227b2858ad6d to your computer and use it in GitHub Desktop.
Save ghBack/e6c0b0b706acac2f3a7d227b2858ad6d to your computer and use it in GitHub Desktop.
A script to install R, Rstudio and Shiny-server on an Ubuntu server
#! /bin/bash
# Ask user for sudo password (to be used when needed)
read -s -p "Enter Password for sudo: " sudoPW
# update CRAN repository below if needed
REPO="'https://cran.rstudio.com/'"
# Based on the instructions on Dean Attali's website:
# https://deanattali.com/2015/05/09/setup-rstudio-shiny-server-digital-ocean/#user-libraries
# add CRAN repository to the repo list (this case for xenial)
UB_VER=$( . /etc/os-release && echo ${VERSION_CODENAME} )
echo $sudoPW | sudo -S sh -c "echo \"deb http://cran.rstudio.com/bin/linux/ubuntu $UB_VER/\" >> /etc/apt/sources.list"
echo $sudoPW | sudo -S sh -c "echo \"deb http://cran.rstudio.com/bin/linux/ubuntu ${UB_VER}-backports main restricted universe\" >> /etc/apt/sources.list"
# add public keys
gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
echo $sudoPW | sudo -S apt-key add `gpg -a --export E084DAB9`
# install nginx, R and Ubuntu dependencies
echo $sudoPW | sudo -S apt-get update
echo $sudoPW | sudo -S apt-get -y install nginx r-base-dev libcurl4-gnutls-dev libxml2-dev libssl-dev gdebi-core \
libcairo2-dev libxt-dev # these two dependencies needed for Cairo
# set default CRAN REPO
echo $sudoPW | sudo -S su - -c "echo \"options(repos=structure(c(CRAN=$REPO)))\" >> /usr/lib/R/Rprofile.site"
# install shiny package
echo $sudoPW | sudo -S su - -c "R -e \"install.packages('shiny')\""
# install RStudio server and shiny-server, parse recent versions from links below
# https://www.rstudio.com/products/rstudio/download-server/
RSTUDIO_DOWNLOAD=`curl https://www.rstudio.com/products/rstudio/download-server/ | grep -Eo "wget .+?rstudio-server-[0-9\.]+-amd64.deb"`
RSTUDIO_FILE=`echo $RSTUDIO_DOWNLOAD | awk -F[/] '{print $NF}'`
echo $RSTUDIO_DOWNLOAD | bash
echo $sudoPW | sudo -S gdebi -n $RSTUDIO_FILE
# https://www.rstudio.com/products/shiny/download-server/
SHINY_DOWNLOAD=`curl https://www.rstudio.com/products/shiny/download-server/ | grep -Eo "wget .+?shiny-server-[0-9\.]+-amd64.deb"`
SHINY_FILE=`echo $SHINY_DOWNLOAD | awk -F[/] '{print $NF}'`
echo $SHINY_DOWNLOAD | bash
echo $sudoPW | sudo -S gdebi -n $SHINY_FILE
# Setup user permissions
echo $sudoPW | sudo -S groupadd shiny-apps
echo $sudoPW | sudo -S usermod -aG shiny-apps $USER
echo $sudoPW | sudo -S usermod -aG shiny-apps shiny
cd /srv/shiny-server
echo $sudoPW | sudo -S chown -R $USER:shiny-apps .
echo $sudoPW | sudo -S chmod g+w .
echo $sudoPW | sudo -S chmod g+s .
# Install additional R packages
echo $sudoPW | sudo -S su - -c "R -e \"install.packages('pacman')\""
# echo $sudoPW | sudo -S su - -c "R -e \"source('https://bioconductor.org/biocLite.R'); biocLite()\"" # uncomment this one and remove "BiocManager" from next line if using R<3.5
echo $sudoPW | sudo -S su - -c "R -e \"pacman::p_install(c('devtools', 'BiocManager', 'tidyverse', 'shinydashboard', 'shinyWidgets', \
'R.utils', 'DT', 'sqldf', 'dbplyr', 'RSQLite','doFuture', 'MonetDBlite','Cairo', 'RColorBrewer'), character.only=TRUE)\""
echo $sudoPW | sudo -S su - -c "R -e \"BiocManager::install(c('Biostrings'))\""
echo "R, Rstudio-server and shiny-server installed!"
echo "Please follow nginx and shiny-server configuration instructions at https://deanattali.com/2015/05/09/setup-rstudio-shiny-server-digital-ocean/#user-libraries"
echo "To add user authentication, please read https://www.r-bloggers.com/add-authentication-to-shiny-server-with-nginx/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment