Shiny (brought by RStudio) is a powerful web framework for building an interactive web applications using R. It is a perfect tool designed for statisticians who do not have any web programming experience.

R is a free software programming language and software environment for statistical computing and graphics. As the time for “Big Data” is coming, R’s popularity has increased substantially in recent years.

What is Shiny Server

Shiny Server is used to put Shiny application on the web.

Shiny Server is designed to serve up multiple Shiny applications on the same server. It handles the job of launching and managing the R processes that run your Shiny apps, and directs web traffic to the correct process based on request URL.

Get EC2 Up and Running

Shiny Server is now only supporting Linux OS, so any Linux/Unix based EC2 instance should be OK to have Shiny Server installed.

The following tutorial is done based on Ubuntu 14.04 LTS 64bit. For other Linux OS, check here for detail.

Add CRAN repository

Shiny Server recommends an installation of R version 3.0 or higher.

# "precise" is for Ubuntu 12.04 LTS
# The CRAN mirror can be changed according to http://cran.r-project.org/mirrors.html
sudo echo 'deb http://cran.cnr.Berkeley.edu/bin/linux/ubuntu trusty/' >> /etc/apt/sources.list

For other version of Ubuntu, you can check here for details.

For Debain system, check here.

Get APT Key

The Ubuntu archives on CRAN are signed with the key of “Michael Rutter marutter@gmail.com” with key ID E084DAB9. So you need to add this to your system in order to sign CRAN packages.

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9

Get Instance Up-to-date

sudo apt-get update

Install R

Install the complete R system.

sudo apt-get install r-base

If you also need to compile R packages from source code (e.g. package maintainers, or anyone installing packages with install.packages()), be sure to install r-base-dev package as well.

sudo apt-get install r-base-dev

Usually, we also install the r-recommended bundle, which includes the following packages:

r-cran-boot
r-cran-class
r-cran-cluster
r-cran-codetools
r-cran-foreign
r-cran-kernsmooth
r-cran-lattice
r-cran-mass
r-cran-matrix
r-cran-mgcv
r-cran-nlme
r-cran-nnet
r-cran-rpart
r-cran-spatial
r-cran-survival

sudo apt-get install r-recommended

If needed to install a “specific” version of R, add a version # following the packages.

sudo apt-get install r-base=3.0.1-1precise0precise2
sudo apt-get install r-recommended=3.0.1-1precise0precise2

Install Extra Packages

In order to have a better run of R, better install the following R packages. Type R to go into R env.

# In R, run
install.packages("bigmemory", repos="http://cran.us.r-project.org")
install.packages("foreach", repos="http://cran.us.r-project.org")
install.packages("iterators", repos="http://cran.us.r-project.org")
install.packages("doMC", repos="http://cran.us.r-project.org")
install.packages("doSNOW", repos="http://cran.us.r-project.org")
install.packages("itertools", repos="http://cran.us.r-project.org")     

Install Shiny & Shiny-Server

Here, the target Shiny-Server version is 1.2.0.

If you are going to install Shiny-Server 0.3.x, you can check here for more details.

Install gdebi-core package to install Shiny Server and its dependencies

sudo apt-get install gdebi-core

Download deb file of Shiny Server to local. The actual file URL depends on the version you need.

sudo wget http://download3.rstudio.org/ubuntu-12.04/x86_64/shiny-server-1.2.0.342-amd64.deb

Install Shiny Server

sudo dgebi shiny-server-1.2.0.342-amd64.deb

Start Shiny Server

To start or stop the server, run the following commands, respectively.

sudo start shiny-server
sudo stop shiny-server

To restart the server you can run:

restart shiny-server

Note that restart will not reread the Upstart definition at /etc/init/shiny-server.conf. So if you have changed, for instance, some environment variables in that file. You will need to stop and start to have those changes take effect.

If you wish to keep the server and all Shiny processes running without interruption, but reload the configuration, you can use the reload command as in:

reload shiny-server

To check the status or retrieve the Process ID associated with shiny-server, run the following:

status shiny-server

Configure Shiny Server

Initially, Shiny Server uses the following configuration file under /etc/shiny-server/shiny-server.conf.

# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;

# Define a server that listens on port 3838
server {
  listen 3838;

  # Define a location at the base URL
  location / {

    # 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;
  }
}

If it does not meet you need, you can customize it. Here are the details.

Peace!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>