[IPython-User] Javascript interaction with python objects in notebook
Fernando Perez
fperez.net@gmail....
Sun Jan 8 00:53:58 CST 2012
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.
Cheers,
f
More information about the IPython-User
mailing list