Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Shiny Server Pro in Docker

This is a Dockerfile for Shiny Server Pro on Ubuntu 14.04. It is based on the rocker-org Shiny image, except that it builds on Ubuntu instead of Debian, and installs Shiny Server Pro instead of Shiny Server.

This Dockerfile also installs some examples from the an old commit of the shiny-examples repo. The purpose of this Dockerfile is to run specific examples that require Shiny Server Pro, and currently can't be run on Shinyapps.io.

NOTE: Building the Docker image requires compiling dplyr, which can consume a lot of memory. If you're running this on a VM, you may need to enable swap for the VM.

Usage:

To build (assuming you're in this directory):

docker build -t ssp-examples .

To run a temporary container with Shiny Server Pro:

docker run --rm -p 3838:3838 ssp-examples

Then you can visit examples at (e.g.):

(If using boot2docker, visit http://192.168.59.103:3838/appdir/.) A full list of the examples is at the shiny-examples repo.

To expose a directory on the host to the container use -v <host_dir>:<container_dir>. The following command will use /srv/shinylog on the host as the directory for logs. Note that if the directories on the host don't already exist, they will be created automatically.

docker run --rm -p 3838:3838 \
    -v /srv/shinylog/:/var/log/ \
    ssp-examples

In a real deployment scenario, you will probably want to run the container in detached mode (-d) and listening on the host's port 80 (-p 80:3838):

docker run -d -p 80:3838 \
    -v /srv/shinylog/:/var/log/ \
    ssp-examples
FROM ubuntu:14.04
MAINTAINER Winston Chang "winston@rstudio.com"
# =====================================================================
# R
# =====================================================================
# Need this to add R repo
RUN apt-get update && apt-get install -y software-properties-common
# Add R apt repository
RUN add-apt-repository "deb http://cran.rstudio.com/bin/linux/ubuntu $(lsb_release -cs)/"
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
# Install basic stuff and R
RUN apt-get update && apt-get install -y \
vim-tiny \
less \
wget \
r-base \
r-base-dev \
r-recommended
# =====================================================================
# Shiny Server Pro
# =====================================================================
RUN apt-get install -y \
gdebi-core \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev \
libxt-dev
# Download and install libssl 0.9.8
RUN wget --no-verbose http://ftp.us.debian.org/debian/pool/main/o/openssl/libssl0.9.8_0.9.8o-4squeeze14_amd64.deb && \
dpkg -i libssl0.9.8_0.9.8o-4squeeze14_amd64.deb && \
rm -f libssl0.9.8_0.9.8o-4squeeze14_amd64.deb
# Download and install shiny server pro
RUN wget https://s3.amazonaws.com/rstudio-shiny-server-pro-build/ubuntu-12.04/x86_64/VERSION -O "version.txt" && \
VERSION=$(cat version.txt) && \
wget "https://s3.amazonaws.com/rstudio-shiny-server-pro-build/ubuntu-12.04/x86_64/shiny-server-commercial-$VERSION-amd64.deb" -O ssp-latest.deb && \
gdebi -n ssp-latest.deb && \
rm -f version.txt ssp-latest.deb
RUN echo "password" | /opt/shiny-server/bin/sspasswd /etc/shiny-server/passwd "manager"
RUN echo "password" | /opt/shiny-server/bin/sspasswd /etc/shiny-server/passwd "sales1"
RUN echo "password" | /opt/shiny-server/bin/sspasswd /etc/shiny-server/passwd "sales2"
#RUN echo "kimpass" | /opt/shiny-server/bin/sspasswd /etc/shiny-server/passwd "kim"
#RUN echo "sampass" | /opt/shiny-server/bin/sspasswd /etc/shiny-server/passwd "sam"
#RUN echo "johnpass" | /opt/shiny-server/bin/sspasswd /etc/shiny-server/passwd "john"
#RUN echo "kellypass" | /opt/shiny-server/bin/sspasswd /etc/shiny-server/passwd "kelly"
#RUN echo "benpass" | /opt/shiny-server/bin/sspasswd /etc/shiny-server/passwd "ben"
#RUN echo "joepass" | /opt/shiny-server/bin/sspasswd /etc/shiny-server/passwd "joe"
RUN R -e "install.packages(c('shiny', 'rmarkdown'), repos='http://cran.rstudio.com/')"
EXPOSE 3838
COPY shiny-server.sh /usr/bin/shiny-server.sh
CMD ["/usr/bin/shiny-server.sh"]
# =====================================================================
# Shiny examples
# =====================================================================
# Get examples from git repo. This downloads the files from the commit just
# before Garrett deleted them from the repo:
# https://github.com/rstudio/shiny-examples/commit/41ff00e
RUN cd /srv/shiny-server && \
wget https://github.com/rstudio/shiny-examples/archive/230acb1990f1ea6049885837eac8e58ed8405f80.zip && \
unzip 230acb1990f1ea6049885837eac8e58ed8405f80.zip && \
rm 230acb1990f1ea6049885837eac8e58ed8405f80.zip && \
mv shiny-examples-230acb1990f1ea6049885837eac8e58ed8405f80/* . && \
rm -rf shiny-examples-230acb1990f1ea6049885837eac8e58ed8405f80
# Packages needed for specific examples
#RUN R -e "install.packages(c('ggplot2', 'lubridate', 'dplyr', 'RSQLite'), repos='http://cran.rstudio.com/')"
RUN R -e "install.packages(c('ggplot2', 'lubridate'), repos='http://cran.rstudio.com/')"
COPY shiny-server.conf /etc/shiny-server/shiny-server.conf
# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;
# Specify the authentication method to be used.
# Initially, a flat-file database stored at the path below.
auth_passwd_file /etc/shiny-server/passwd;
# Define a server that listens on port 3838
server {
listen 3838;
# Define a location at the base URL
location / {
required_user manager sales1 sales2;
# Only up tp 20 connections per Shiny process and at most 3 Shiny processes
# per application. Proactively spawn a new process when our processes reach
# 90% capacity.
utilization_scheduler 20 .9 3;
# Host the directory of Shiny Apps stored in this directory
site_dir /srv/shiny-server;
# Log all Shiny output to files in this directory
log_dir /var/log/shiny-server;
# When a user visits the base URL rather than a particular application,
# an index of the applications available in this directory will be shown.
directory_index on;
}
}
#!/bin/sh
# Make sure the directory for individual app logs exists
mkdir -p /var/log/shiny-server
chown shiny.shiny /var/log/shiny-server
exec shiny-server >> /var/log/shiny-server.log 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment