[IPython-User] [IPython-dev] "Freezing" dynamic content with nbconvert, was ANN: Exhibitionist
Tue Mar 19 13:06:22 CDT 2013
I've been looking for a way to showcase (and dogfood) the
library I released a couple of weeks ago, Exhibitionist
Yesterday, I started work enhancing the wonderful notebooks on
MCMC released by @CamDavidsonPilon at:
with interactive views of various kinds.
I wanted to share a pleasent success I had in "freezing" a dynamic Exhibitionist
based on d3 and data streaming via AJAX, into a static view which is stored with
the notebook, and viewable in nbviewer.
Here's a screenshot:
the upper view is dyanmic, and you can control the lambda parameter of the
exponential distribution plotted in realtime.
The lower view is the result of hitting the "freeze" button in the upper right corner,
and is saved with the notebook, viewable even without exhibitionist installed
- completely reproducable.
A nice feature of this, is that you can interactively "tweak" your plot parameters
until you're satisfied, and then freeze the plot for "publication".
I plan to working on gradually enhancing all the book chapters in this way,
and release the notebooks on github.
If anyone has a need to do something similar, here are the technical bullet
points for how this works:
- the dynamic view lives in an embedded iframe
- the HTML5 postmessage API is used for exchanging messages between
the iframe and the IPPython main window.
- when the "freeze" button is clicked, the svg blob generated by d3 (using
json data fetched over AJAX, from an exhibitioinst server running n the IPython
kernel process) is sent over to the IPython window.
- the listener catching the message introspects the cells using the IPython
js object, and jquery to replace the IFrame with the svg blob, and to overwrite
the cell output area so that the svg data is serialized when the notebook
- Styiing the svg is an interesting problem. You can include the css ctyles
for the plot in the IPython notebook, or, if you inline the styles as svg element
attributes, the plot becomes completely self-contained. I'm using the latter for now.
This was really excited to get working, I wasn't even sure it's possible. It is.
----- Original Message -----
From: Matthias BUSSONNIER
Sent: 03/07/13 07:39 PM
To: IPython developers list
Subject: Re: [IPython-dev] "Freezing" dynamic content with nbconvert, was ANN: Exhibitionist
Le 7 mars 2013 à 17:48, yoval p. a écrit :Hi,
My suggestion is that the display protocol be modified so that the semantics of
`_repr_html_` would mean static HTML only, and a new `_repr_jshtml_` (however named)
magic method would be supported, under which objects would implement
We are also certain that we can have a more general approach.
(Keep in mind that, thinking of the display protocol as only html/js notebook/qtconsole is also much too restrictive)
In short, we believe using _display_json_ is the right way and is enough.
Most of the time, when you display js, the only thing you want to send are data that need to be interpreted.
This allow also to depend on other installed plugin without having to embed lib like jQuery etc at every call.
In framework like chromium embeded, you cannot in any way execute code that are in script tag. The js
**have to** be part of the application at launch time.
it will just not be supported.
As for nbviewer, if there is a _repr_json_ , nothing prevent it from using it in html to have dynamic represent,
but the same json could be use to make a Tikz representation in latex, or even multiple plugin could be able to interpret the same json.
So after long repletion, I am convince that json-repr is the way to go.
We'll still consider the suggestion of course, and discussion are welcomed.
_______________________________________________IPython-dev mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-User