useR 2015 and htmlwidgets
I’ve been wondering if this year’s useR conference foreshadowed some gigantic groundbreaking change in the world of R. The previous useR conference was a sort of catalyst for dplyr package and operator %>%. The profession (especially from California) had been familiar with both solutions for several months but useR 2014 transferred the admiration for pipes from early adopters to the (almost) whole community.
Did anything of that sort happen during this year’s useR? The problem with revolutions is that when they take place, nobody notices them. However, looking back in time we see them quite clearly. With that in mind I would like to take the risk and play fortuneteller.
In my opinion the dark horse of the conference was the package htmlwidgets.
Why?
Ok, first I will explain what it actually is (and if the explanation does not explain, you may visit the project’s website and see for yourself). The package htmlwidgets is a framework allowing one to create interactive java script based widgets in R. Such plug-in can be embedded in HTML5 (what means on presentation’s slides, in knitr documents, shiny applications). At the same time the plug-ins do not need R on the server side to remain interactive as they are written in java script (while shiny requires R and as a result one has to find a sever, maintain necessary libraries, …).
It doesn’t seem like much.
Just a short code that makes it easier to embed java script at HTML site created by R.
However, on the other hand, popularity of shiny package seems to be soaring recently. In tandem with docker it forms a brilliant tool for easy creation of complex websites for data exploration. Yet it has one huge drawback which is its reliance on R sever as far as interaction is concerned. This feature requires lot of resources. It may fail when the server has a ‘weak moment’. It is useful for prototyping but risky in production (unless we have some scalable backend embedded in AWS or some other infinite machine). The htmlwidgets lets us get rid of the necessity of R on serverside. Objects from R are rendered into java script.
It offers a practically free access to a growing base of various libraries including almost everything based on D3.js.
For instance, the following two lines of code in R generate a picture which can be published on a blog (the figure is interactive, feel free to rotate/zoom/flip).
library(threejs) scatterplot3js(iris$Sepal.Length, iris$Sepal.Width, iris$Petal.Length, color=c("red","blue","green")[iris$Species])
(click to interact)
The following three lines create a heat map which can be placed at www without any additional server.
library(PogromcyDanych) library(d3heatmap) setLang() rownames(cats_birds) = cats_birds[,1] d3heatmap(cats_birds[,c(2,3,4,6)], scale="column", colors="Blues")
(click to interact)
More information about this package can be found in the presentation by Joe Cheng from RStudio.