[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:
state.json='{"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"}' # 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( document.getElementById('MotionChartID6db280db') ); 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\\"}" ]; chart.draw(data,options); }
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( document.getElementById('MotionChartID47a55df7') ); 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}"; chart.draw(data,options); }
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.
May 30, 2011 at 1:16 PM
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
May 31, 2011 at 8:46 AM
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:
therefore
makes more sense; it gives a better isomorphism between R’s
and
json
I have to take a closer look!
May 31, 2011 at 8:57 AM
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:But this is easy to distinguish from a one-element list via
class()
:But it’s not so easy to distinguish from a several-element vector:
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?May 31, 2011 at 2:46 PM
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.
May 31, 2011 at 10:30 PM
Hi Markus:
That’s great news. Thanks for all your hard work on googleVis, and especially for helping me track down my problem. I was just able to post a couple of motion charts of airline traffic statistics on my work blog thanks to the RJSONIO downgrade workaround.
Thanks again!
Jeffrey
June 14, 2011 at 3:14 PM
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 …
BTW
A working NULL ->null->NULL chain is new for versions>0.7 imho
regards