googleVis-0.2.4 requires older version of RJSONIO (0.5-0) #rstats

[Update: the new release of googleVis accounts for changes in RJSONIO’s handling of backslashes, so you probably won’t need the older version.]

Something has apparently changed in the way RJSON’s toJSON() function works which is causing all sorts of extra escape characters (backslashes) to appear in the googleVis-generated JavaScript, at least when trying to set a visualization’s initial state. This bogus code causes the browser’s JavaScript engine to choke just before it can call chart.draw(), so you don’t see the Flash visualization at all–just a blank space with the pretty footer.

This is at least the case on Mac OS 10.6.7 and Markus Gesmann gets all the credit for tracking it down.

Here’s an example state string which selects a couple of bubbles to be labeled (“Oranges” and “Apples”) and sets the time to start about half-way through:


# create the motion chart
M=gvisMotionChart(Fruits, "Fruit", "Year", options=list(state=state.json))

Here’s the output in question using the current RJSONIO 0.7:

> cat(M$html$chart['jsDrawChart'])

// jsDrawChart
function drawChartMotionChartID6db280db() {
  var data = gvisDataMotionChartID6db280db()
  var chart = new google.visualization.MotionChart(
  var options ={};
options["width"] = [    600 ];
options["height"] = [    500 ];
options["state"] = [ "{\\"xAxisOption\\":\\"3\\",\\"xZoomedDataMin\\":81,\\"playDuration\\":15000,\\"sizeOption\\":\\"_UNISIZE\\",\\"xZoomedDataMax\\":111,\\"xLambda\\":1,\\"dimensions\\":{\\"iconDimensions\\":[\\"dim0\\"]},\\"yZoomedDataMax\\":91,\\"duration\\":{\\"multiplier\\":1,\\"timeUnit\\":\\"Y\\"},\\"orderedByX\\":false,\\"xZoomedIn\\":false,\\"yZoomedDataMin\\":71,\\"showTrails\\":false,\\"orderedByY\\":false,\\"iconType\\":\\"BUBBLE\\",\\"uniColorForNonSelected\\":false,\\"yZoomedIn\\":false,\\"nonSelectedAlpha\\":0.4,\\"yLambda\\":1,\\"time\\":\\"2010\\",\\"yAxisOption\\":\\"4\\",\\"iconKeySettings\\":[{\\"LabelY\\":27,\\"key\\":{\\"dim0\\":\\"Apples\\"},\\"LabelX\\":42}],\\"colorOption\\":\\"6\\"}" ];

And here’s working code from RJSONIO 0.5:

> cat(M$html$chart['jsDrawChart'])

// jsDrawChart
function drawChartMotionChartID47a55df7() {
  var data = gvisDataMotionChartID47a55df7()
  var chart = new google.visualization.MotionChart(
  var options ={};
options["width"] =    600;
options["height"] =    500;
options["state"] = "{\"sizeOption\":\"5\",\"nonSelectedAlpha\":0.4,\"xLambda\":1,\"iconType\":\"BUBBLE\",\"yZoomedDataMax\":91,\"iconKeySettings\":[{\"LabelY\":-124,\"LabelX\":-160,\"key\":{\"dim0\":\"Oranges\"}},{\"LabelY\":53,\"LabelX\":37,\"key\":{\"dim0\":\"Apples\"}}],\"xZoomedIn\":false,\"orderedByX\":false,\"showTrails\":false,\"yZoomedIn\":false,\"yZoomedDataMin\":71,\"xZoomedDataMin\":81,\"orderedByY\":false,\"xAxisOption\":\"3\",\"yAxisOption\":\"4\",\"uniColorForNonSelected\":false,\"duration\":{\"timeUnit\":\"Y\",\"multiplier\":1},\"time\":\"2009\",\"yLambda\":1,\"xZoomedDataMax\":111,\"dimensions\":{\"iconDimensions\":[\"dim0\"]},\"colorOption\":\"2\",\"playDuration\":15000}";

Maybe this post can help others avoid the blank look I had on my face as I kept staring at a blank page in my browser.

About these ads

6 Responses to “googleVis-0.2.4 requires older version of RJSONIO (0.5-0) #rstats”

  1. wactbprot Says:

    A first point which comes into my mind is:
    I find the 0.7X version of RJSONIO more consequent, because of the fact that R don’t have scalar values.
    returning a e.g. [ 600 ] instead of 600
    gives a better isomorphism between R’s list() and json

    • Jeffrey Breen Says:

      Hi wactbprot:

      I like the formatting of your comment on tumblr, so I have reproduced here:

      A first point is:

      I find the 0.7X version of RJSONIO more consequent, because of the fact that R don’t have scalar values:

      > a <- 2
      > a
      [1] 2


      options["width"] = [    600 ];

      makes more sense; it gives a better isomorphism between R’s




      I have to take a closer look!

    • Jeffrey Breen Says:

      To the content of your post — you raise a good point, but I think the ambiguity in R is not with list()‘s but with vectors:

      > a = 2
      > a
      [1] 2

      But this is easy to distinguish from a one-element list via class():

      > a.list = list(2)
      > a.list
      [1] 2
      > class(a.list)
      [1] "list"
      > class(a)
      [1] "numeric"

      But it’s not so easy to distinguish from a several-element vector:

      > b = c(2,4,6)
      > b
      [1] 2 4 6
      > class(b)
      [1] "numeric"

      length() can be used, but as you point out, how are we to know that the one-element vector is really supposed to be a scalar?

      > length(a)
      [1] 1
      > length(b)
      [1] 3
  2. Markus Says:

    Soon we will publish a new version of googleVis on CRAN which addresses the new formatting of RJSONIO. You can get a working version via subversion from the googleVis project site already.

  3. wactbprot Says:

    I’ve _tried_ to visualize for my own use the relation between R and JSON here implemented by RJSONIO. The plot is valid for 0.7-2 and 0.7-3. Maybe it’s useful for others too …
    A working NULL ->null->NULL chain is new for versions>0.7 imho

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 63 other followers

%d bloggers like this: