The trouble is that the map is saved as a local HTML file (rChart_map.html
) and is hence not accessible to nbviewer when you are trying to view it online.
Even if you upload rChart_map.html
to the gist, it won't show up due to path issues. Locally, you need to refer to it as /files/rChart_map.html
in your IPython notebook, whereas online, it has a different path. I had posted this issue earlier on twitter using the #IPython tag, but got no responses on how to debug.
So where does that leave us. Well, fortunately, most modern browsers allow an iframe to contain inline HTML using the srcdoc
tag. This allows the generated .ipynb
file to be standalone, as seen here, at the end of the file.
The key is to use the following code. The first line creates an iframe with inline html of the map and stores it in the python variable map2
. The second line imports the necessary python modules and the third line displays the HTML. Note that we use h2[0]
, since map2
is an array, due to conversion from R, which is vectorized.
map2 = %R paste(capture.output(map$show('iframesrc', cdn = TRUE)), collapse = '\n')
from IPython.display import display, HTML
HTML(map2[0])
For this to work, you will need to have rCharts
version > 0.4.1.
I am interested in making it easier for rCharts
to be used in IPython notebooks. So any suggestions/feedback is welcome.