Вопрос

I have been able to embed this map in an IPython Notebook (which is sweet), but I am not clear on how I can share this with folks not using the Notebook. I am familiar with the bl.ocks.org viewer. It's great for standalone examples, but I am looking to share the rest of the analysis in the Notebook along with interactive charts. Neither the HTML conversion of the Notebook nor the nbviewer rendering can locate the map (I get a 404 message).

After the first 404 (with this gist), I changed the viewer function to capture the github location of the map file (V2). I am not yet clear why, but that change stopped nbviewer from even rendering the surrounding materials. Any thoughts on a better way to go about this?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top