Other sites

Deploying R, RStudio and Shiny applications on Unbuntu Server

In this post, we are going to see how to deploy R, RStudio, and Shiny apps on a virtual server.

The post won’t focus on Shiny programming aspect, neither on Unbuntu programming, however, the tutorial is self-sufficient. Only by following the different steps, you’ll get a working server and Shiny app.

1. Choosing your virtual server provider

There are a lot of virtual server providers available on the web, among them:

Microsoft Azure

AWS

IBM softlayer

DigitalOcean

The offers are more or less the sames, for this tutorial, you are going to need a virtual server with at least 2GB of RAM and Unbuntu installed. Below is a comparison of these service providers (Since it’s far from being exhaustive, tell me if you know better options).

Service provider

Specifications

Monthly price

AWS (t2.small)

2GB RAM/1 CPU/AWS storage

16,06$

DigitalOcean

2GB RAM/2 CPU/40 GB SSD

20$

Microsoft Azure (A1)

1.75 GB RAM/1 CPU/40 GB disk

20.09$

IBM SoftLayer

2GB RAM/1 CPU/ 25GB disk

35$

In this tutorial we will use DigitalOcean (Still most of the tutorial should be working on most other Unbuntu server), you can get a 10$ discount using this link, which is enough to run the server for 2 weeks for free.

Choosing DigitalOCean was mainly motivated by its low cost, the easy configuration and the great amount of tutorials available to deploy a DigitalOcean server. If you already have an other service provider, the tutorial should work fine too.

2. Setting up the Unbuntu droplet

On digital ocean, server are call droplet, first you need to complete your account creation, then let’s create an Unbuntu droplet:

3.b.Creation of an admin user

You may want to create a new admin user, to avoid working with the root privilege:

$ adduser user_name

Now we need to grant this user sudo (admin) privileges:

$ usermod -a -G sudo user_name

You then will be asked to enter a password and some information (name, room number, …)

And we can now modify our SSH connection to login with this user account:

Windows and putty:
Connection->Data->Autologin username (change it from root to the user_name you entered)

4. Installing R and Shiny

To install R, you just have to follow this tutorial from DigitalOcean: Tutorial R base .

A few comments:

The R version should the most recent one (3.3.2), you can check it using version in R.

Don’t forget to run R with: (thus the package will be available for all users).

$ sudo -i R

Once you run R with the previous command, R terminal should start, you can quit R by using q(). You can now install the shiny package in the R console with:

install.packages("shiny")

And you can check the installation by trying to load the library and one of its function:

>library("shiny")
>fluidPage()

5. Installing R Studio server:

Now let’s install RStudio to have a complete R environnement. Futhermore having RStudio on your server will allow you to code there directly and to avoid some problems when transitioning from your laptop to the server.