[IPython-User] Javascript interaction with python objects in notebook

Brian Granger ellisonbg@gmail....
Sun Jan 8 14:26:43 CST 2012

On Sat, Jan 7, 2012 at 10:53 PM, Fernando Perez <fperez.net@gmail.com> wrote:
> Hi Chris,
> On Sat, Jan 7, 2012 at 9:13 AM, Chris Currivan <ccurrivan@gmail.com> wrote:
>> I'm hoping to create something like an interactive plot with
>> checkboxes for which lines to display. I can create the html objects
>> from markdown or _repr_html_/display/publish_html. I can refer the
>> click events to javascript defined elsewhere in a markdown cell,
>> however that javascript can't return any information to the python
>> code. Is is possible to use the notebook's internal interface to allow
>> user javascript to send python calls to the kernel?
> Sort of... You can put code like this in a markdown cell:
> <script>IPython.notebook.kernel.execute("z=10")</script>
> or in the repr_html of an object and then display it.  Just look at
> 'z' afterwards, and it will be 10.
> However, we seem to have a very odd bug in that using these tricks and
> saving, creates a file that then confuses the notebook on load.  Will
> need to investigate...

Hmm, didn't know that.  It is probably that the <script> tag is run
when the notebook is loaded, but that happens before the kernel has
been created.

>> Is there an easy way to access matplotlib images in html/javascript in
>> order to display them some way besides in a column below whatever was
>> published last?
> No, unfortunately not yet.
>> Are there any examples of _repr_javascript_? I've tried a few
>> variations of returning javascript code and none seem to execute. An
>> example that didn't work:
> I'm not sure the repr_javascript really works well yet.  But if you
> change that to _repr_html_ keeping the code otherwise identical,
> you'll get the alert to pop up.

Correct, the repr_javscript doesn't do anything yet.  It may take some
time to work all of this out as there are some subtle issues here.
But this is definitely something we want to figure out and get

> Cheers,
> f
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

More information about the IPython-User mailing list