[IPython-User] [IPython-dev] "Freezing" dynamic content with nbconvert, was ANN: Exhibitionist

yoval p. y-p@gmx....
Tue Mar 19 13:06:22 CDT 2013


Hi,

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:
https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers

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:
https://f.cloud.github.com/assets/1820866/277146/5e11823a-90be-11e2-917a-a317e7702318.png

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
is saved.
- 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.

Cheers,
Yoval
----- 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

Hi Yoval, 

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
dynamic views.


Thoughts?

What you describe look IMHO to much to the current _repr_html_/_repr_javascript_, we had quite some time to think about it, 
and something in those line was my first idea, but dealing with displaying javascript is both much more complicated than it looks.
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.
Javascript plugin should be js files loaded as extension, you shouldn't need to display generated code. 
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.

With the architecture we planed, rewriting _display_javascript_ should be totally possible as simple small plugin
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. 

-- 
Matthias

_______________________________________________IPython-dev mailing list
 IPython-dev@scipy.org 
http://mail.scipy.org/mailman/listinfo/ipython-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20130319/29c68dc9/attachment.html 


More information about the IPython-User mailing list