Skip to content
Prev 38087 / 63424 Next

Scripting SVG with R

This is slightly tangential, but I would just add some notes related
to things that I had worked on (in various stages of completion).
This relates more to parsing SVG and Javascript from within R, rather
than R from within Javascript:

1) I wrapped most of the Protovis primitives in an R package called
webvis (http://cran.r-project.org/web/packages/webvis/).  If you're
not familiar, Protovis is an excellent low-level plotting package in
Javascript (http://vis.stanford.edu/protovis/) out of Jeffrey Heer's
lab at Stanford (http://vis.stanford.edu/).  Protovis produces SVG
graphics as the output.  As a first pass, I decided to just use the
web browser to parse the javascript.  You can see how this works by
calling demo("playfairs.wheat") or looking at the plot.webvis help
examples.

2) My goal was to have the next version of webvis parse the javascript
directly in R.  To that end, I started working on another package that
would wrap the javax.script.* library using rJava.  This works for me,
and it allows you to pass code in any scripting language that runs on
the JVM (including Jython, Jaskell, Clojure, and Javascript).  The
problem is that you need more than javascript parsing in order to use
something like Protovis: you need the complete web browser context.
You can get this by using env-js (http://www.envjs.com/).  But that
leads to another problem: the version of the javascript parser (called
Rhino) in javax.script wasn't the latest, so I would need to use Rhino
directly (you can see part of my discussion that here:
http://stackoverflow.com/questions/2664578/using-javax-script-or-rhino-to-run-javascript-in-java-with-browser-context-e-g).
 That's where I stopped.

What would the end result of webvis be so far as it pertains to your
problem?  With a small amount of effort, it would be pretty straight
forward to create interactive graphics that are pure javascript from
R.  I had envisioned that this would be more useful for an interactive
R session, but I know of one project (RNode) that's currently using it
from a browser through Rserve (see
http://squirelove.net/r-node/doku.php).

Hope that this is useful.

Regards,
Shane
On Fri, Oct 15, 2010 at 11:06 AM, Gabriel Becker <gmbecker at ucdavis.edu> wrote: