Hosting Shiny on Amazon EC2

May 30, 2015
By

(This article was first published on Exegetic Analytics » R, and kindly contributed to R-bloggers)

I recently finished some work on a Shiny application which incorporated a Random Forest model. The model was stored in a RData file and loaded by server.R during initialisation. This worked fine when tested locally but when I tried to deploy the application on shinyapps.io I ran into a problem: evidently you can only upload server.R and ui.R files. Nothing else.

Bummer.

I looked around for alternatives and found that Amazon Elastic Compute Cloud (EC2) was very viable indeed. I just needed to get it suitably configured. A helpful article documented the process from an OSX perspective. This is the analogous Ubuntu view (which really only pertains to the last few steps of connecting via SSH and uploading your code).

Create an Account

The first step is to create an account at aws.amazon.com. After you’ve logged into your account you should see a console like the one below. Select the EC2 link under Compute.

AWS Management Console-002.bmp

Next, from the EC2 Dashboard select Launch Instance.

EC2 Management Console-003.bmp

Step 1: There is an extensive range of machine images to choose from, but we will select the Ubuntu Server.

EC2 Management Console-004.bmp

Step 2: Select the default option. Same applies for Step 3, Step 4 and Step 5.

EC2 Management Console-005.bmp

Step 6: Choose the security settings shown below. SSH access should be restricted to your local machine alone. When you are done, select Review & Launch.

EC2 Management Console-007.bmp

Step 7: Create a new key pair. Download the key and store it somewhere safe! Now press Launch Instances.

EC2 Management Console-008.bmp

The launch status of your instance will then be confirmed.

EC2 Management Console-009.bmp

At any later time the status of your running instance(s) can be inspected from the EC2 dashboard.

EC2 Management Console-010.bmp

SSH Connection

Now in order to install R and Shiny we need to login to our instance via SSH. In the command below you would need to substitute the name of your key file and also the Public DNS of your instance as the host name (the latter is available from the EC2 Dashboard).

$ ssh -i AWS-key.pem [email protected]

Installing R

Once you have the SSH connection up and running, execute the following on your remote instance:

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

Installing Shiny

To install the Shiny package, execute the following on your remote instance:

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

During the installation a directory /srv/shiny-server/ will have been created, where your applications will be stored.

Installing and Testing your Applications

Transfer your applications across to the remote instance using sftp or scp. Then move them to a location under /srv/shiny-server/. You should now be ready to roll. You access the Shiny server on port 3838. So assuming for example, your application resides in a sub-folder called medal-predictions, then you would browse to http://ec2-52-24-93-52.us-west-2.compute.amazonaws.com:3838/medal-predictions/.

The post Hosting Shiny on Amazon EC2 appeared first on Exegetic Analytics.

To leave a comment for the author, please follow the link and comment on their blog: Exegetic Analytics » R.

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.

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)