Before I develop a feature to it’s full extent I like to spend a little time making a proof of concept (POC). POCs help me to get a handle of the functions and libraries I need for a task and help me get a birds-eye view of the limitations so I don’t go too far down the wrong road. Frameworks like Shiny are great if you want to develop and host a full-fledged app but it is a bit verbose for a proof of concept.
Tools like Browserify make it easy to write what amounts to a web application without a lot of the work. No doubt they come with their share of headaches but they are great for a POC. Projects like Require Bin, Jsfiddle and jsbin are also useful when drawing up these kinds of POCs.
My Use Case
What I want to do is for some data with intersectionality create an UpSet plot. Upset is an interesting concept and you can read the paper here for more details: http://vcg.seas.harvard.edu/publications/upset-visualization-intersecting-sets.
R has a package called UpSetR which makes these plots and I figured I could leverage them. If I could find a way to send JSON to this function and have it produce a plot that’ll be dandy wouldn’t it?
The API is documented fairly well but there are some gaps in documentation and examples that can make it a little tricky to use. The components of the application are simple. First you need access to some R instance. Instead of making all of R available each OpenCPU call makes a small subset of R available . In this example I loaded a the UpSetR library in the line:
From there I used Jquery to set up some event listeners, like a button click and attributes that exist in the DOM. I then used the *call *function to actually call the R function *upset *which makes my plot. That’s pretty simple.
You don’t necessarily need to know R on a deep level to get working with opencpu.js but an understanding on R is helpful. Since you’re working primarily with functions it can come in handy to write your own R functions or troubleshoot if extra parameters are needed.