Danny Malter

Data Science Manager - Accenture
M.S. in Predictive Analytics - DePaul University

Danny Malter

Me
Malter Analytics
GitHub
LinkedIn
YouTube Channel
Twitter
Kaggle

Other Work
General Assembly
AriBall

Media
Built In

Guide to Hosting Shiny Apps on Amazon EC2 for Mac OSX

Setting up an Amazon EC2 Instance

plot of chunk shinyImage1

plot of chunk shinyImage2

Connect to Server vis SSH

Open the Terminal in your Mac and type the following command:

ssh -i [path to your AWS keypair .pem file] ubuntu@[your public DNS address]

Example:

ssh -i /Users/Malter/Documents/AWSkeypair.pem ubuntu@ec2-52-1-117-130.compute-1.amazonaws.com

You will be promted about whether you are sure that you want to connect, and should press enter.

Install R - Official Instructions

Run the following commands in the Terminal.

sudo apt-get update
sudo apt-get install r-base
sudo apt-get install r-base-dev

Install the Shiny package, Shiny Server, and other packages that you may need. Down the road, other packages can be uploaded through a drag and drop process with and SFTP client and will discussed later.

To install the Shiny package, run the following command in the Terminal.

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

To install Shiny Server, run the following commands in the Terminal.

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

Install an SFTP client to Upload Files

This process can all be done in the Terminal, but a perhaps easier way to upload R files to the Server is through an SFTP client, such as Cyberduck.

plot of chunk shinyImage3

Once connected, you will be automatically placed into the directory /home/ubuntu. Since we have already installed Shiny and Shiny Server, you can go into the directoy /srv/shiny-server to see a sample Shiny application. This is the direcotry where all of your Shiny app files will go.

To give Cyberduck permission in all of the directories within the server, type into the Terminal:

sudo chown -R [Cyberduck username] [directory where you want write permissions]

Example:

sudo chown -R ubuntu /srv/*

There should already be a folder in the /srv/shiny-server directory called “sample-apps”. You can view this sample application by typing into the url:

Example:
http://ec2-52-1-117-130.compute-1.amazonaws.com:3838

Host Multiple Shiny Application through this Server

In order to host other applications, simply create a new folder in /srv/shiny-server and drag in the respective ui, server and other files that go with the application. For example, I have created a new folder called “HR-Hitter” located at /srv/shiny-server/HR-Hitters.

Example:
http://ec2-52-1-117-130.compute-1.amazonaws.com:3838/HR-Hitters/
Note: If the ec2 link does not work, it means the Amazon Instance has been turned off. The same app can also be seen <a href=”https://danmalter.shinyapps.io/HR-Hitters”target=”_blank”>here</a> through RStudio.

plot of chunk shinyImage4

Upload more R Packages to Shiny Server

As noted earlier, you can upload R packages one of two ways, through the terminal or with a drag and drop method using an SFTP client. We already discussed how to upload a new package in the Terminal, so now i will show you how to upload a new package using Cyberduck.

open /Library/Frameworks/R.framework/Versions/3.1/Resources/library
sudo chmod -R 777 /usr/local/lib/R

Note: This command is through Ubuntu, so you will have to either be connected to your Server or reconnect using:

ssh -i [path to your AWS keypair .pem file] ubuntu@[your public DNS address]

Keeping R up to Date

sudo su
echo "deb http://www.stats.bris.ac.uk/R/bin/linux/ubuntu precise/" >> /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
apt-get update
apt-get upgrade
comments powered by Disqus