<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/hosting-rstudio-server-on-azure/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.jumpingrivers.com/posts/2017/rstudio_azure_cloud_1/"> R on The Jumping Rivers Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<ul>
<li><a rel="nofollow" href="http://blog.jumpingrivers.com/posts/2017/rstudio_azure_cloud_1/#cant-be-bothered-reading-tell-me-now" target="_blank">Can’t be bothered reading, tell me now</a></li>
<li><a rel="nofollow" href="http://blog.jumpingrivers.com/posts/2017/rstudio_azure_cloud_1/#getting-started" target="_blank">Getting started</a></li>
<li><a rel="nofollow" href="http://blog.jumpingrivers.com/posts/2017/rstudio_azure_cloud_1/#setting-up-r" target="_blank">Setting up R</a></li>
<li><a rel="nofollow" href="http://blog.jumpingrivers.com/posts/2017/rstudio_azure_cloud_1/#opening-ports-ready-for-rstudio" target="_blank">Opening ports ready for RStudio</a></li>
<li><a rel="nofollow" href="http://blog.jumpingrivers.com/posts/2017/rstudio_azure_cloud_1/#installing-rstudio" target="_blank">Installing RStudio</a></li>
<li><a rel="nofollow" href="http://blog.jumpingrivers.com/posts/2017/rstudio_azure_cloud_1/#nicer-urls" target="_blank">Nicer URLs</a></li>
<li><a rel="nofollow" href="http://blog.jumpingrivers.com/posts/2017/rstudio_azure_cloud_1/#adding-ssl" target="_blank">Adding SSL</a></li>
</ul>
</div>
<div>
<h2>Can’t be bothered reading, tell me now</h2>
<p>Host RStudio server on an azure instance. Configure the instance to access RStudio with a <em>nice</em> url</p>
</div>
<div>
<h2>Getting started</h2>
<p><a rel="nofollow" href="https://azure.microsoft.com/" target="_blank">Azure</a> is cloud computing framework provided by Microsoft, the same idea as AWS by Amazon. In this post, we’ll describe how to use Azure to run <a rel="nofollow" href="https://www.rstudio.com/products/rstudio/download-server/" target="_blank">RStudio Server</a> in the cloud.</p>
<p>Unfortunately, things don’t start well – Microsoft have made an endurance test of getting started with Azure. The first stop is the <a rel="nofollow" href="https://azure.microsoft.com/en-gb/" target="_blank">Azure</a> web-page. On this page</p>
<p><img src="https://i1.wp.com/blog.jumpingrivers.com/img/2017/azure_home.png?w=450" data-recalc-dims="1"></p>
<p>click on <strong>Free Account</strong> and follow the instructions. This is a bit of painful process that will require</p>
<ul>
<li>Email confirmation</li>
<li>Text confirmation</li>
<li>Credit Card confirmation</li>
</ul>
<p>Eventually you should get to the dashboard page!</p>
<p><img src="https://i0.wp.com/blog.jumpingrivers.com/img/2017/azure_dashboard.png?w=450" data-recalc-dims="1"></p>
<p>Clicking on <code>Create Resources</code> will take you to the marketplace</p>
<p><img src="https://i0.wp.com/blog.jumpingrivers.com/img/2017/azure_marketplace.png?w=450" data-recalc-dims="1"></p>
<p>Selecting <code>Ubuntu Server</code> will launch a dialogue box with four steps:</p>
<ul>
<li>Step 1: Basics: configuration settings
<ul>
<li><strong>Name</strong>: A name for the virtual machine, e.g. <code>rstudio</code></li>
<li><strong>User name</strong>: The master user who will have <code>sudo</code> access, e.g. <code>userX</code></li>
<li><strong>Authentication type</strong>: Either choose ssh or enter a password</li>
<li><strong>Resource group</strong>: Since this your first instance, create a new one, say <code>rstudio-group</code></li>
<li><strong>Location</strong>: where will your machine be located</li>
</ul>
</li>
<li>Step 2: Virtual machine size
<ul>
<li>Select the machine you want. Choose the smallest for the purposes of this exercise</li>
</ul>
</li>
<li>Step 3: Settings
<ul>
<li>Nothing to change here</li>
</ul>
</li>
<li>Step 4: Summary
<ul>
<li>Click create and we’re good to go!</li>
</ul>
</li>
</ul>
<p>After around a minute or so, your virtual machine will be ready.</p>
</div>
<div>
<h2>Setting up R</h2>
<p>The next step is to <code>ssh</code> into your instance. On the dashboard screen, click on the new box that shows your virtual machine. Select <code>Networking</code>. Near the top of the screen will be a Public IP address, of the form: XXX.XXX.XXX.XXX. In my instance, the IP address is 52.233.194.195</p>
<p><img src="https://i2.wp.com/blog.jumpingrivers.com/img/2017/azure_networking.png?w=450" data-recalc-dims="1"></p>
<p>Make a note of your address. Next <code>ssh</code> into your instance via</p>
<pre><code>ssh userX@XXX.XXX.XXX.XXX</code></pre>
<p>To ensure that ubuntu is up-to-date on our virtual machine, we invoke super sudo powers. First we update the list of ubuntu packages</p>
<pre><code>sudo apt-get update</code></pre>
<p>Then we upgrade as necessary</p>
<pre><code>sudo apt-get upgrade</code></pre>
<p>Now we get on with the business of installing R. To use the latest version we need to add a new <a rel="nofollow" href="https://cran.r-project.org/bin/linux/ubuntu/README.html" target="_blank">repository</a></p>
<pre><code>sudo add-apt-repository ppa:marutter/rrutter</code></pre>
<p>Then update again and install base R</p>
<pre><code>sudo apt update
sudo apt-get install r-base</code></pre>
<p>Depending on what R packages you want to install it’s worth installing a couple of other things at this point</p>
<pre><code>sudo apt-get install libxml2 libxml2-dev # igraph
sudo apt-get install libcairo2-dev # Graphics packages
sudo apt-get install libssl-dev libcurl4-openssl-dev #httr</code></pre>
<p>With an eye to the future it’s also worth installing <code>apache2</code> to help with redirects</p>
<pre><code>sudo apt-get install apache2</code></pre>
</div>
<div>
<h2>Opening ports ready for RStudio</h2>
<p>Whenever you access a web-page, the browser specifies a <em>port</em>. For standard http pages, we use port 80, for secure https pages, we use port 443. For example, when we type</p>
<pre><code>https://www.jumpingrivers.com</code></pre>
<p>in the browser, this is converted to</p>
<pre><code>https://www.jumpingrivers.com:443</code></pre>
<p>By default our azure instance only has port 22 open (the port used for ssh communication). To access RStudio, we’ll need to open the following ports</p>
<ul>
<li>80 (for http)</li>
<li>443 (for https); only required if we implement SSL</li>
<li>8787 – the default RStudio port. In the last section, we’ll remove this, but just now it’s handy to have it open for testing.</li>
</ul>
<p>Under <code>Networking</code>, click <code>Add inbound port rule</code> and add the three ports (80, 443, 8787):</p>
<p><img src="https://i2.wp.com/blog.jumpingrivers.com/img/2017/azure_dashboard_port.png?w=450" data-recalc-dims="1"></p>
<p>If everything is working, you should be able to enter <code>XXX.XXX.XXX.XXX</code> in your browser and you’ll see the <code>Apache2 Ubuntu Default Page</code> with the title. <strong>It works!</strong></p>
</div>
<div>
<h2>Installing RStudio</h2>
<p><a rel="nofollow" href="https://www.rstudio.com/products/rstudio/download-server/" target="_blank">Installing RStudio</a> server is now relatively easy:</p>
<pre><code># Check the above link for updates to the version
sudo apt-get install gdebi-core
wget https://download2.rstudio.org/rstudio-server-1.1.383-amd64.deb
sudo gdebi rstudio-server-1.1.383-amd64.deb</code></pre>
<p>If everything works correctly, you should be able to view rstudio server via</p>
<pre><code>XXX.XXX.XXX.XXX:8787</code></pre>
<p>If the page <em>hangs</em>, double check you have opened port 8787 under the network settings.</p>
</div>
<div>
<h2>Nicer URLs</h2>
<p>The first step is to access the page via a standard URL and not an IP address. In the main dashboard screen, under all resources, click on</p>
<pre><code>rstudio-ip Public IP address</code></pre>
<p>Then select configuration. In the text box under DNS Label, enter text, e.g. <code>rstudio-myname</code>. So in my case, I have used <code>rstudio-jumpingrivers</code></p>
<p><img src="https://i0.wp.com/blog.jumpingrivers.com/img/2017/azure_dashboard_ip.png?w=450" data-recalc-dims="1"></p>
<p>This means we can now access RStudio via</p>
<pre><code>rstudio-jumpingrivers.westeurope.cloudapp.azure.com:8787</code></pre>
<p>Getting users to type the port number isn’t ideal. What we would like is for users to type</p>
<pre><code>rstudio-jumpingrivers.westeurope.cloudapp.azure.com/rstudio</code></pre>
<p>This involves configuring Apache. First navigate to <code>/etc/apache2/sites-available</code>, e.g.</p>
<pre><code>cd /etc/apache2/sites-available</code></pre>
<p>Next create a file called <code>rstudio.conf</code>. Using your favourite text editor, e.g. vim or nano. Note that this file is very much space sensitive, so check it carefully.</p>
<pre><code></code></pre>
<p>Then enable the necessary Apache modules</p>
<pre><code>sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_html
sudo a2enmod proxy_wstunnel
sudo a2enmod rewrite</code></pre>
<p>Finally, restart Apache</p>
<pre><code>sudo a2ensite rstudio.conf
sudo service apache2 restart  </code></pre>
<p>You should now be able to access RStudio via</p>
<pre><code>rstudio-jumpingrivers.westeurope.cloudapp.azure.com/rstudio/</code></pre>
</div>
<div>
<h2>Adding SSL</h2>
<p>In theory it should be straightforward to add SSL support using <a rel="nofollow" href="https://letsencrypt.org/" target="_blank">Let’s Encrypt</a>. However, I’ve found that you hit rate limiters since the domain is azure.com. However, if we register our own domain, we can easily add SSL support. This will be the subject of our next blog post.</p>
<div>
<h4>References</h4>
<ul>
<li><a rel="nofollow" href="https://mgw.dumatics.com/rstudio-server-setup-with-ssl-behind-apache-proxy-server/" target="_blank">https://mgw.dumatics.com/rstudio-server-setup-with-ssl-behind-apache-proxy-server/</a></li>
</ul>
<hr>
<p><a rel="nofollow" href="https://www.jumpingrivers.com/?utm_source=blog&utm_medium=image&utm_campaign=2017azure" target="_blank"><img src="https://i1.wp.com/blog.jumpingrivers.com/img/logos/300_125.jpg?w=456" data-recalc-dims="1"></a></p>
</div>
</div>
	<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://blog.jumpingrivers.com/posts/2017/rstudio_azure_cloud_1/"> R on The Jumping Rivers 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/cGwlU7990iQ" height="1"></a></div>