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

MinRK benjaminrk@gmail....
Sun Jan 8 01:04:05 CST 2012


On Sat, Jan 7, 2012 at 22:53, 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...
>
> > 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.
>

It doesn't even not work 'really well' - javascript is not one of the
representations the notebook is aware of, so it's simply ignored.  This
would be the reason your script is not executed.  Obviously, it should be
added, but repr_html would be the way to do it for now.  The only
difference would be wrapping the javascript in a <script> tag.

-MinRK



>
> Cheers,
>
> f
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20120107/399c4299/attachment-0001.html 


More information about the IPython-User mailing list