Setting up an AWS instance for R, RStudio, OpenCPU, or Shiny Server

[This article was first published on ipub » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

While most web-developers have worked with Amazon AWS, Microsoft Azure, or similar platforms before, this is still not the case for many R number crunchers. Especially researchers at academic institutions have less exposure to these commercial offerings. Time to change that!

In this post, we explain how to set up an Ubuntu server instance on AWS, and how to install R on it. In later posts, we will explain how to add RStudio server and Shiny Server Open Source.

Our main goal is to get you started quickly, so we ignore many of the useful options offered by AWS, such as e.g. security aspects.

Alternatives

You might as well chose another platform, and we do not claim that AWS is the best or the cheapest. So do let us know if you think there are reasons why some other cloud service is better suited for R developers.

For a start, depending on your use case, any of the following alternatives might be useful:

  • Another cloud service (Azure, Digital Ocean, Rackspace,  ElasticHost, etc.)
  • Docker (container on any machine, including an AWS instance, or on your development machine, be it Linux or Windows)

Step by step guide to create your AWS instance

Prerequisite: AWS account

If you do not have an AWS account yet, it’s time you get one here. You’ll get a free micro instance for a year or so. This means that you can run this tutorial at no cost. If you already have an AWS account, you’re ready for the next step: Creating an AWS instance.

1. Create AWS EC2 Ubuntu instance

Within the AWS management console, go to EC2 and create a new Ubuntu instance:

Click Select on the latest Ubuntu Server, and then click Review and Launch. Ignore the warnings about the security groups, we’ll worry about that later.

Next, the wizard will ask you about the key pair. The AWS key pair is needed to ssh into your Ubuntu instance, and we’ll use it later to connect to our AWS instance and install R. If you have created an EC2 instance before, you can re-use its keys. Otherwise, create and download a new key pair:

Save the *.pem file to your local disk. Then click Launch Instances

2. Connect to your Ubuntu cloud instance

The wizard will take you to the EC2 instances dashboard, where you’ll find your new instance, initially in a pending state. You can give it a name by clicking into the Name field (AWS Tutoril in the example below):

Once the Status Checks indicate that all checks are done, we are ready to connect to our instance: Select the instance and click on Connect. The browser displays detailed connection instructions, including a link to even more details. If your local machine is a Linux or Mac, you’re ready to go and you can follow directly the instructions provided by AWS.

Connect to your Ubuntu cloud instance from Windows

On Windows, you need an additional software, such as Putty, and you’ll need to convert your pem key file into a ppk file with puttygen. You’ll find detailed instructions in this EC2 installation guide.

If you follow through, upon first connection you’ll receive a security alert, looking like this:

You can – at least in the context of the hands-on tutorial – ignore it by clicking on Yes. If prompted for a user name, enter ubuntu.

3. Upgrade Ubuntu

What now follows is not specific to AWS. You would need to perform the following steps on any Ubuntu system.

You should now see a window that looks something like this:

Congrats, you’re connected to your AWS instance!

First thing you might want to do is to upgrade your system, by typing:

sudo apt-get dist-upgrade

This will download and install latest versions. When prompted, type Y. You might also get a screen like this:

I suggest to install the package maintainer’s version.

4. Installing R

Time to install R! Unfortunately, this is not as easy as it should be, but that’s due to Ubuntu, and not AWS. Anyway, it’s not that hard either. Specifically, to make sure that we get the latest R packages, we need to add a CRAN mirror to the sources.list file. And we need to install r-base. More details can be found here, but what you essentially want to do is this:

apt-get upgrade

Between commands, hit Y if prompted.

Now you need to install R, by typing:

sudo su
echo "deb http://cran.rstudio.com/R/bin/linux/ubuntu trusty/" >> /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
apt-get update
apt-get install r-base

5. Running R on Ubuntu

Again, that’s not different than running R on any Ubuntu system. If you have done

sudo su
  as above, simply type

R

otherwise, type

sudo -I R

And off you go! To quit, type

quit()

If you enjoyed this tutorial, come back for more. We’ll add tutorials on how to install RStudio Server, Shiny Server, and how to secure them!

The post Setting up an AWS instance for R, RStudio, OpenCPU, or Shiny Server appeared first on ipub.

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

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)