Docker is this wonderful new way to play around with appliances without hurting your machine or stealing away heaps of time. Personally, I found this high-level overview of Docker clear and to the point even though the reality with respect to Azure is somewhat more complex than they say. There are tons of interesting packages on the Docker hub and I found out that installing Docker on Mac is really a breeze. The Kitematic site is where you can download a client and it automatically install a VirtualBox if needed. While one could in principle run docks on a native machine it’s understandable that the containers run on top of a virtual one to keep things safe and contained. It seems to install a lightweight Linux but you don’t even have to look at it since everything can be accessed via the clean Kitematic client (which by the way is just a web page)Kitematic

Click and install, play and test, it’s all that simple.

Now what does it all have to do with R? As you probably know R has its own Shiny framework for delivering dynamic web content but it’s somewhat off the mainstream way of developing things and deploying it requires some cash. It’s similar to the way things are in Mathematica where one can also do as good as everything but everything is different than one is used to. So, when I discovered OpenCPU I was rather pleased to see that one can use standard ajax, jQuery, Angular and whatnot to develop R-powered, interactive sites. That is, you can develop R packages running on the server but present and manipulate everything using standard HTML/JS frameworks. The OpenCPU framework itself can be installed in various ways but the easiest one is by using Docker; there is a downloadable container and you can install it using Kitematic in a snap. Cherry on the cake, you get R-Studio Server with it.

Once installed you can open up your browser or use the Kitematic shortcut to which displays the default Apache Debian page. Browsing to the OpenCPU page allow you to interactively test the JS API. Just clicking on the Ajax Request button will return the list of R libraries, for instance.

So, how does one access the container and the how to install custom R libraries?

Kitematic has a shortcut to the bash terminal where you can manage the machine. In particular, if you simply type ‘R’ you will be in the R environment wherein you can install all you like. One thing I found somewhat surprising is that packages are compiled on the spot, unlike R-Studio where the compiled versions are installed. This means that some compilations fail to find the necessary bundles:

ERROR: configuration failed for package ‘XML’

Thanks to StackOverflow (how did past generations live without?) errors like this can easily be fixed;

sudo apt-get update
sudo apt-get install libxml2-dev

The R-Studio Server environment can be accessed via but surprise surprise, you need to log in.



RServer users are normal Ubuntu users and you simply need to type ‘add user’ with sudo in the terminal to give yourself and account. Once logged in you will see the familiar R environment inside your browser. Ain’t it awesome.

RServer Screen

OpenCPU applications are just normal R packages which contain both R and HTML/JS code. Very much like any other mixed technology in fact; ASP.Net, PHP and such. They all mix server and client files into one application box.

For example, use in the container terminal the following to install some sample OCPU packages

#install apps: 'stocks', 'markdownapp' and 'nabel'
install_github(c("stocks", "markdownapp", "nabel"), username="opencpu")

and navigate to to see something like

OCPU Stocks

At this point you are free to use any client library you like; KendoUI, Angular and so on. Much easier than Shiny, much more close to other web frameworks.

One wished that this technology would be integrated with, say, ASP.Net but maybe the upcoming the SQL Server integration with R is the answer in this direction.