Installing shiny and shiny-server (on localhost)

Assuming you already have a working R installation on a Debian-like system.

First step, install the shiny R package.

sudo su - -c "R -e \"install.packages('shiny', repos='http://cran.rstudio.com/')\""

Download and install the shiny server software from RStudio (the shiny package is installed using gdebi, so you need to install that too if you don’t already have it).

sudo apt-get install gdebi-core
wget http://download3.rstudio.org/ubuntu-12.04/x86_64/shiny-server-1.3.0.403-amd64.deb
sudo gdebi shiny-server-1.3.0.403-amd64.deb

RStudio offers shiny-server for free with the AGPL v3 license but with the limit of a single R process per shiny application, and without support for authentication or SSL. The former limit is not an issue for lightweight shiny apps, but the latter can be problematic if you intend to host public-facing shiny apps on your own server. One possible way of getting around this limit could be to setup a reverse proxy using an SSH tunnel to access the shiny app, but I have not been able to make such a setup work myself.

Running the shiny app

I use a dashboard to keep track of my project’s sample matrix (as we chemists like to call it). It’s run using a short bash script with essentially the following contents:

#!/bin/bash
PORT=$(shuf -i 2000-10000 -n 1)
# write the port number to file
echo $PORT > /path/to/shinyapp/directory/shiny.port
nohup R -e "shiny::runApp('/path/to/shinyapp/directory', port = $PORT)"

The bash script is called from an Ubuntu autostart script so that the dashboard starts on system login. Accessing it is then as simple as pointing your browser to localhost:<port-number>. Since we don’t want to check the port number manually, something along these lines is used to start the browser:

#!/bin/bash
PORT=$(</path/to/shinyapp/directory/shiny.port)
s="http://localhost:$PORT"
google-chrome $s

Of course, randomly assigning the shiny app port number is not necessary. It is simply a remnant from the development phase of this app - changing the port number on each launch of the app made debugging easier (one less variable to worry about…).

The finished dashboard app contains a lot of links to local pdf files, so depending on browser you may have to disable the restriction to open file:///-type hyperlinks.