I've uploaded the notebook here for convenience.
http://nbviewer.jupyter.org/gist/finaiized/ad8836b64a874518d32c40e7a4a03966
On Friday, 5 May 2017 09:48:49 UTC-7, Dominic Kuang wrote:
>
> I've been trying to figure out how to use comms to communicate from Python
> <-> JS. Using the following simple example:
>
> # Cell 1
> from IPython.kernel.comm import Comm
>
> def handle_comm_message(message):
> print(message)
>
> comm = Comm('comm-target-name')
> comm.on_msg(handle_comm_message)
>
> // Cell 2
> %%javascript
> var IPython = window.IPython IPython.notebook.kernel.comm_manager.
> register_target('comm-target-name', function(comm, data) {
> comm.on_msg(function(msg) { console.log(msg) });
> comm.send({'data': 'sent from the client'})
> });
>
>
> # Cell 3
> comm.send(data={'data': 'sent from python'})
>
> I can reliably get Python -> JS to work. In this case, after executing
> Cell 3, I receive the message in the console containing "Sent from Python"
> as expected. However, I am unable to trigger the sending from client. I am
> not sure if I have something set up incorrectly or I am simply
> misunderstanding how comms work. Any help would be appreciated! Thanks!
>
--
You received this message because you are subscribed to the Google Groups
"Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jupyter/efe9a2f0-c7f3-419e-8b15-b0cb3b952067%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.