Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Notebook HTML/JS to send messages to Python code #2313

Closed
inducer opened this issue Aug 17, 2012 · 8 comments
Closed

Allow Notebook HTML/JS to send messages to Python code #2313

inducer opened this issue Aug 17, 2012 · 8 comments
Milestone

Comments

@inducer
Copy link

inducer commented Aug 17, 2012

Hi all,

I think it would be terrific if IPython could replicate this:

http://reference.wolfram.com/mathematica/ref/Manipulate.html

Since the notebook already has jquery UI, this is missing pretty much only one component, and that is being able to route AJAX messages back to Python callbacks. API-wise, I'm thinking something like:

IPython.notebook.register_call("changed-foo-slider", my_callable)

def my_callable(json_obj):
    plot(...)

And on the JS side, provide a function call_python("changed-foo-slider", json_obj). Since which cell is being updated is not explicitly represented in IPython, there would have to be a bit of magic in the background to make sure that cell is remembered at registration time. But that doesn't sound too frightening.

Of course, one could also then build some canned slider wigetry, to match the Mathematica feature, but that would just be icing. :)

Andreas

@minrk
Copy link
Member

minrk commented Aug 17, 2012

This is already done in 0.13. Kernel.execute takes callbacks. See various widget examples for running code from JavaScript.

@minrk minrk closed this as completed Aug 17, 2012
@inducer
Copy link
Author

inducer commented Aug 17, 2012

Sorry for being dense--can't find any examples of this. I did find this:

https://github.com/ipython/ipython/tree/master/docs/examples/widgets/directview

but it seems unrelated. Also grep widget here:

https://github.com/ipython/ipython/tree/master/docs/examples/notebooks

comes up empty.

Thanks in advance for your help!

@minrk
Copy link
Member

minrk commented Aug 17, 2012

Sorry, we really need to improve discoverability of these things.

here is an example of using javascript to do interactive plots. And #1697 is where this code was principally introduced.

@ellisonbg
Copy link
Member

The directview widget is the only example of this that we have where the JS
code calls back into the kernel.

But, we have plans to support the manipulate style capability in the
notebook. If you are serious in working on that please let us know, we
have done quite a bit of design work behind the scenes.

On Fri, Aug 17, 2012 at 9:39 AM, Min RK notifications@github.com wrote:

Sorry, we really need to improve discoverability of these things.

herehttps://github.com/ipython/ipython-in-depth/blob/master/notebooks/Z%20Callbacks.ipynbis an example of using javascript to do interactive plots. And
#1697 #1697 is where this code
was principally introduced.


Reply to this email directly or view it on GitHubhttps://github.com//issues/2313#issuecomment-7828072.

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

@inducer
Copy link
Author

inducer commented Aug 20, 2012

Great--glad to hear that this is possible. As a side issue, the Bessel example doesn't seem to show properly until you edit the cell with the plot div and re-render it.

I can't afford to work on this stuff right now, unfortunately, but I'll try to report all the issues I come across. Thanks for all your hard work on this!

@keflavich
Copy link

First, +1 to improving discoverability.

The example doesn't seem to work in nbviewer - is there any way to enable that? It's probably low-priority, but it would be cool.

@Carreau
Copy link
Member

Carreau commented Nov 13, 2012

is there any way to enable that?
Nop, nbviewer is a pure viewer.
There is no kernel involve.
Allowing arbitrary python to be runed on server side is too dangerous.
Maybe smth like sage with one time use cell... but this would be a lot heavier than nbviewer.

@aflaxman
Copy link

This amazing example has moved. Here is a link that I think will persist: https://github.com/ipython/ipython-in-depth/blob/a5b04442bd70f6e0d4a1f7a31667cd6d09027061/notebooks/old/Z%20Callbacks.ipynb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants