Install Shiny Server for R on Ubuntu the Right Way

October 15, 2015
By

(This article was first published on R Tricks – Data Science Riot!, and kindly contributed to R-bloggers)

Is it time to spin up a new instance of Shiny Server? This tutorial is baseed on a fresh install of Ubuntu Server 14.04, but I’m sure it could be tweaked to work on RHEL or CentOS as well. There’s no real secret sauce to the install but there are several “gotcha’s” that most people overlook. The walk-through below can get you up and running in just a few minutes.

1. Make sure you have the latest version of R.
If you don’t have the R environment on your box already. See here for the install.

sudo apt-get update && sudo apt-get upgrade

2. Install shiny package for R via command line.

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

3. Make sure you have these dependencies.

sudo apt-get install -y libcurl4-openssl-dev 
sudo apt-get install -y libxml2-dev

…and don’t forget Java!

sudo apt-get install -y openjdk-7-jdk
export LD_LIBRARY_PATH=/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server
sudo R CMD javareconf  

4. IMPORTANT:
Change R package directory from user-based to system-wide. Find the below lines in your Renviron file and use your favorite text editor to swap the comment hashes to the configuration below.

sudo nano /usr/lib/R/etc/Renviron

Your Renviron file should look like this when you’re done.
#R_LIBS_USER=${R_LIBS_USER-‘~/R/x86_64-pc-linux-gnu-library/3.0’}
R_LIBS_USER=${R_LIBS_USER-‘~/Library/R/3.0/library’}

5. Check lib paths in R to make sure your package library changed correctly.
“/usr/local/lib/R/site-library” should be the first of the library paths.

R
.libPaths()

5. Make your new package lib readable for Shiny Server.

sudo chmod 777 /usr/lib/R/site-library

6. Install a few R packages.
It will ask if you want to create a personal directory, select “no.” You want them in the universal directory you just created.

R
install.packages(c('RJDBC', 'RJSONIO', 'rmarkdown', 'dplyr'))

7. Install Shiny Server.

sudo apt-get install -y gdebi-core
sudo 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

8. Set permissions for Shiny Server directory so outside users can see your apps.

sudo chmod -R 777 /srv

BOOM!
Open browser and point it to localhost:3838. Your Shiny Server should be started and running on port 3838!
shiny-server-alive

To leave a comment for the author, please follow the link and comment on their blog: R Tricks – Data Science Riot!.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)