<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/setting-up-rstudio-server-quickly-on-amazon-ec2/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.win-vector.com/blog/2018/01/setting-up-rstudio-server-quickly-on-amazon-ec2/"> R – Win-Vector Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I have recently been working on projects using <a rel="nofollow" href="https://aws.amazon.com/ec2/" target="_blank">Amazon EC2 (elastic compute cloud)</a>, and <a rel="nofollow" href="https://www.rstudio.com/products/rstudio/" target="_blank">RStudio Server</a>. I thought I would share some of my working notes.</p>
<p>Amazon EC2 supplies near instant access to on-demand disposable computing in a variety of sizes (billed in hours). RStudio Server supplies an interactive user interface to your remote <a rel="nofollow" href="https://www.r-project.org/" target="_blank">R</a> environment that is nearly indistinguishable from a local RStudio console. The idea is: for a few dollars you can work interactively on R tasks requiring hundreds of GB of memory and tens of CPUs and GPUs.</p>
<p>If you are already an Amazon EC2 user with some Unix experience it is very easy to quickly stand up a powerful R environment, which is what I will demonstrate in this note.</p>
<p><span></span></p>
<p>To follow these notes you must already have an Amazon EC2 account, some experience using the AWS (Amazon Web Services) console, and managing ssh key pairs for use with EC2. Start by copying down the path where you have stored your secret half of your ssh key pair (your key should always be stored somewhere safe, such as a private and encrypted disk volume; if you don’t have a key pair you will be prompted create one during machine launch).</p>
<p>You can set up an RStudio Server instance as follows.</p>
<p>Choose Ubuntu Server as your AMI (Amazon Machine Image) type. This step is choosing your operating system, the script we will use was developed for <a rel="nofollow" href="https://en.wikipedia.org/wiki/APT_(Debian)" target="_blank">apt package management</a>– so we suggest using the Ubuntu operating system.</p>
<p><img border="0" src="https://i0.wp.com/www.win-vector.com/blog/wp-content/uploads/2018/01/NewImage-6.png?w=660" alt="NewImage" title="NewImage.png" data-recalc-dims="1"></p>
<p>Then choose your hardware or machine type. I will show a t2.micro instance (1 virtual CPU, 1 GB memory), but there are a lot of bigger machine types available (including up to 96 VCPUs, hundreds of GB memory, and GPU compute instances specialized for deep learning tasks).</p>
<p><img border="0" src="https://i0.wp.com/www.win-vector.com/blog/wp-content/uploads/2018/01/NewImage-7.png?resize=660%2C348" alt="NewImage" width="450" title="NewImage.png" data-recalc-dims="1"></p>
<p>Now copy the IPv4 DNS name Amazon assigns to your instance (as shown below).</p>
<p><img border="0" src="https://i2.wp.com/www.win-vector.com/blog/wp-content/uploads/2018/01/NewImage-8.png?resize=660%2C367" alt="NewImage" width="450" title="NewImage.png" data-recalc-dims="1"></p>
<p>In our case we have:</p>
<ul>
<li>Path to key: /Volumes/Private/Accounts/wvdbkp.pem.txt</li>
<li>IPv4 DNS name: ec2-35-166-235-208.us-west-2.compute.amazonaws.com</li>
</ul>
<p>Now download and run the following <a rel="nofollow" href="https://gist.github.com/JohnMount/3694b155d2d184d263e4e34c6ae4a943" target="_blank">bash script</a> on your local (or client) machine (this is assuming you have a <a rel="nofollow" href="https://en.wikipedia.org/wiki/Bash_(Unix_shell)" target="_blank">bash shell</a> and Unix components, which are available on OSX, Linux, BSD, and even Windows; we have only tested this from an OSX client).</p>
<p>In our case we run the script in a bash shell with the arguments as follows:</p>
<pre>
   bash confEc2RServer.bash \
          /Volumes/Private/Accounts/wvdbkp.pem.txt \
          ec2-35-166-235-208.us-west-2.compute.amazonaws.com
</pre>
<p>You would run the script with your own ssh key path and your server IPv4 DNS name.</p>
<p>The script combines some ideas from <a rel="nofollow" href="https://www.manning.com/books/deep-learning-with-r" target="_blank"><em>Deep Learning with R</em>, François Chollet with J. J. Allaire, Manning 2018</a> and <a rel="nofollow" href="http://course.fast.ai/" target="_blank">Jeremy Howard’s <em>Practical Deep Learning For Coders</em></a> with our own experiences working with EC2. The script will produce output for about 3 minutes, when it stops producing output (but is still running) it has switched from installation to running a <a rel="nofollow" href="https://en.wikipedia.org/wiki/Tunneling_protocol" target="_blank">ssh tunnel</a> to direct web-requests targeting your local machine to appear as local requests on the remote server.</p>
<p>At this point you direct your web browser to <code>http://127.0.0.1:8787</code> and login with the user name “<code>ruser</code>” and password “<code>ruser</code>“.</p>
<p>At this point you should see a RStudio Server Console and you should be ready to work.</p>
<p><img border="0" src="https://i1.wp.com/www.win-vector.com/blog/wp-content/uploads/2018/01/NewImage-9.png?w=660" alt="NewImage" title="NewImage.png" data-recalc-dims="1"></p>
<p>The instance type we have configured includes a local PostgreSQL database (user name “<code>ruser</code>” and password “<code>ruser</code>“). Both the Web-Server and database default to only accepting connections that are considered “local” by the remote server. We are able to access the RStudio Server Console through our ssh tunnel, and the database is only available to processes local to the server. If you end the script you are running on your client machine, you close the ssh tunnel (and lose access to the remote server). We haven’t configured any GPU features such as CUDA, tensorflow, or Keras (however that is only one or two lines more and available from the appendix of <em>Deep Learning with R</em>).</p>
<p>And that is it. Don’t forget to copy results off the server when you are done and to dispose of the server by moving its instance state to “Terminate” in the AWS console (this frees the virtual machine, and usually destroys all storage associated with the machine; this is critical to do so that you don’t experience continuing fees for a machine you are done with).</p>
<p><img border="0" src="https://i0.wp.com/www.win-vector.com/blog/wp-content/uploads/2018/01/NewImage-10.png?resize=660%2C429" alt="NewImage" width="450" title="NewImage.png" data-recalc-dims="1"></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.win-vector.com/blog/2018/01/setting-up-rstudio-server-quickly-on-amazon-ec2/"> R – Win-Vector Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/aUHvBfISYkU" height="1"></a></div>