Including googleVis output in a blogger post

It seems that you cannot include Google Visualisation Charts into a blog post directly.
So, I tried to include the output of a googleVis function as a gadget, but also unsuccessfully.
Although you can include gadgets into your site template, it doesn't seem to work with blog posts. So, here is the trick which works for me: the iframe tag.
The following geo map is included as
<iframe width="100%" height="400px" frameborder="0" src="">

As you can see, the chart itself is actually displayed in a page hosted by Dropbox and only inserted into this post via the iframe-tag.

For those of you, who would like to replicate the plot of Hurricane Andrew, here is the R code:
AndrewGeoMap <- gvisGeoMap(Andrew, locationvar='LatLong', numvar='Speed_kt',
                          region='US', dataMode='Markers'))
print(AndrewGeoMap, file="~/Dropbox/Public/AndrewGeoMap.html")
Created by Pretty R at

Correction (18 October 2011)

I just figured out that we can actually embed a chart into a blogger post directly. You can literately copy and paste the code directly into the post. However, it doesn't seem to be displayed with MS Internet Explorer.

Anyhow, here is the example from above again:

print(AndrewGeoMap, "chart", file="~/Desktop/AndrewGeoMap.js")

Now I copied and pasted the content of that file below:


jose said...

Very interesting.

GiYeulBae said...

Hi there,

Thank you very much for this tutorial. But it seems that my code has a problem.

I simply did copy and paste the output contents of "*.html" file into into a blogpost editting window (html editer), and saved it.

The problem is that I was able to see the contents only in the "preview" mode but not in the *real* mode.

Can you guess why this is?

Markus Gesmann said...

I find the above approach with hosting the html file somewhere else and using iframe to insert googleVis output most reliable.

However, you can try to copy only the chart element itself.
Suppose your googleVis output is stored in the variable M, e.g.
M <- gvisMotionChart(Fruits, "Fruit", "Year"), then copy only the output of print(M, 'chart') into your web site.

Liton said...

Cheap web
hosting in Bangladesh.

Post a Comment