Posts tagged “shiny”

Shiny Server on WebFaction

Update: WebFaction released today a one-click installed for node.js, obviating Step 2 below. Leaving it in here for posterity.

Shiny “makes it super simple for R users like you to turn analyses into interactive web applications that anyone can use.” It’s a powerful tool with a relatively simple syntax. It’s great for local apps — but I wanted to set up a web-based app that others could access and that wasn’t beholden to Shiny and RStudio’s excellent beta server platform.

I host this site and a few others at WebFaction — an awesome service with little to no downtime, fast servers, and relatively flexible restrictions. Getting Shiny up and running on WebFaction required a little work.

Step 1: SSH into WebFaction. Follow the instructions on their website for your specific server(s).

Step 2: Make a source directory. Download and install node.js.

mkdir src
cd src
wget 'http://nodejs.org/dist/v0.10.20/node-v0.10.20.tar.gz'
tar -xzf node-v0.10.20.tar.gz
cd node-v0.10.20
python2.7 configure --prefix=$HOME
make PYTHON=python2.7
make PYTHON=python2.7 install

export NODE_PATH="$HOME/lib/node_modules:$NODE_PATH"
echo 'export NODE_PATH="$HOME/lib/node_modules:$NODE_PATH"' >> $HOME/.bashrc 

Step 3: Download and install R.

#install R
wget 'http://cran.us.r-project.org/src/base/R-3/R-3.0.2.tar.gz'
tar -xzf R-3.0.2.tar.gz
cd R-3.0.2
./configure --prefix $HOME
make
make install

Step 4: Make a temp/tmp/temporary director.

cd $HOME
mkdir tmp
chmod 777 tmp
TMPDIR=$HOME/tmp
export TMPDIR

Step 5: Download Shiny from source and install using NPM.

git clone https://github.com/rstudio/shiny-server.git
npm install -g shiny-server/

installing from NPM directly did not work — Shiny would not launch. I believe this is because you’re not allowed root access on WebFaction shared accounts.

Step 6: Launch R and install whatever packages you need.

install.packages('ggplot2')
install.packages('data.table')
devtools::install_github("ShinyDash", "trestletech")
devtools::install_github("shiny-incubator", "rstudio")

Step 7: Want plots to work? In your Shiny app’s global.R file, set

options(bitmapType = 'cairo')

Next up: a cron job to keep a Shiny instance running or to restart it if it goes down… and putting Shiny behind some light authentication to prevent pre-release apps from general consumption.

all rights reserved
snarglr is written & maintained by ajay pillarisetti



click here to turn on all posts