<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Rstudio | Algorist</title><link>https://www.algorist.co.uk/tag/rstudio/</link><atom:link href="https://www.algorist.co.uk/tag/rstudio/index.xml" rel="self" type="application/rss+xml"/><description>Rstudio</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-gb</language><lastBuildDate>Sat, 30 Jan 2021 00:00:00 +0000</lastBuildDate><image><url>https://www.algorist.co.uk/images/icon_hu1a112552fd764c0568141c667be1573d_16776_512x512_fill_lanczos_center_2.png</url><title>Rstudio</title><link>https://www.algorist.co.uk/tag/rstudio/</link></image><item><title>Using Rstudio Server with docker</title><link>https://www.algorist.co.uk/post/using-rstudio-server-with-docker/</link><pubDate>Sat, 30 Jan 2021 00:00:00 +0000</pubDate><guid>https://www.algorist.co.uk/post/using-rstudio-server-with-docker/</guid><description>
&lt;script src="https://www.algorist.co.uk/post/using-rstudio-server-with-docker/index.en_files/header-attrs/header-attrs.js">&lt;/script>
&lt;p>It’s taking a long time to run my genetic algorithm optimisation models recently. So much so that I’ve been looking at offloading processes to other computers lying idle on the network. The &lt;a href="https://github.com/Daveyr/armr">armr&lt;/a> project aims to do this with parallel processing and Rstudio server docker images running on the raspberry pi but this is a work in progress currently, chiefly due to having to build Rstudio server from source.&lt;/p>
&lt;p>In the meantime I have managed to run Rstudio server in a Docker container on my personal laptop, logging into it on my work laptop. Here’s how I did it, using the image provided by the &lt;a href="https://www.rocker-project.org/">Rocker project&lt;/a>.&lt;/p>
&lt;div id="on-the-host-machine" class="section level2">
&lt;h2>On the host machine&lt;/h2>
&lt;p>Assuming you already have docker installed, run the below code in a terminal on the host machine.&lt;/p>
&lt;pre class="bash">&lt;code>docker pull rocker/rstudio
docker run --rm -p 8787:8787 -e PASSWORD=&amp;quot;password&amp;quot; rocker/rstudio&lt;/code>&lt;/pre>
&lt;p>The default user name is “rstudio”. If you want to set the user name, add &lt;code>-e USER="user"&lt;/code> to the command above.&lt;/p>
&lt;p>As easy as that. To make the image usable we would have to create a new dockerfile based on this image and add run commands that install packages within R. For example,&lt;/p>
&lt;pre class="bash">&lt;code>from rocker/rstudio
RUN R -e &amp;quot;install.packages(&amp;#39;tidyverse&amp;#39;)&amp;quot;&lt;/code>&lt;/pre>
&lt;p>The base &lt;code>armr&lt;/code> dockerfile shows how to do this with an install script that reads a requirements.txt file - much quicker than installing each package individually. For saving work, you’ll also need to add a volume tag to the docker run command, e.g.,&lt;/p>
&lt;pre class="bash">&lt;code>docker run --rm -v $(pwd):home/user/ -p 8787:8787 -e USER=&amp;quot;user&amp;quot; -e PASSWORD=&amp;quot;password&amp;quot; rocker/rstudio&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="on-the-external-machine" class="section level2">
&lt;h2>On the external machine&lt;/h2>
&lt;p>To access from another computer on the network, open a browser and navigate to &lt;code>hostname:877&lt;/code>, where hostname is the hostname of the computer running the container. This can be found by running &lt;code>hostname&lt;/code> on it from the terminal (Linux only). If you want to access Rstudio server on the go, away from home, then you will need to do the following.&lt;/p>
&lt;ul>
&lt;li>Issue a static IP address to the host computer, most easily done using your router&lt;/li>
&lt;li>Set up port forwarding to forward port 8787 from the static IP to the outside world&lt;/li>
&lt;li>Read up on security settings in Rstudio server and implement them! These are likely to include IP whitelisting, certificate only authentication, banning IP addresses after several failed attempts (see &lt;em>fail2ban&lt;/em>) and more&lt;/li>
&lt;/ul>
&lt;/div></description></item></channel></rss>