How does "stream" message, sent as reply to comm, bound to cell?

37 views
Skip to first unread message

Ilya Kazakevich

unread,
Sep 23, 2019, 12:44:56 PM9/23/19
to jup...@googlegroups.com
Hello,
I have the following code

```
btn = widgets.Button(description='Medium')
display(btn)
def btn_eventhandler(obj):
    print('Hello from the {} button!'.format(obj.description))
btn.on_click(btn_eventhandler)
``` 

When I click on the button, it sends comm message to python side.
Python replies with "stream" message.

As I understand, button widget uses it's model to send comm message.
Model may have more than one view. 
So, how does jupyter know which cell should be used to output this stream?

I know that for regular code execution it registers callback and uses "parent" header of reply, and I am sure something similar takes place here, but I don't see any callback registered by view nor by model.

Thank you.
Ilya.



Jason Grout

unread,
Sep 23, 2019, 1:01:35 PM9/23/19
to Project Jupyter

In the classic Notebook, the view registers a display callback that puts any output coming back from the kernel in the cell containing the view. The process for getting that callback right is a bit convoluted, involving asking the widget manager for the right callback, etc. The relevant code is at https://github.com/jupyter-widgets/ipywidgets/blob/a311d753385f0867c34525eacad9496108e43cc1/widgetsnbextension/src/manager.js#L311-L335

In JupyterLab, right now nothing is done with the output, so the output essentially disappears: . We are working on a logging extension (hopefully merged for jlab 1.2) that will log a message with any output returned from the kernel.

In the docs, we also encourage people to use the OutputWidget to explicitly capture output if that's what you want: https://ipywidgets.readthedocs.io/en/latest/examples/Output%20Widget.html#Debugging-errors-in-callbacks-with-the-output-widget

Thanks,

Jason


--
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 jupyter+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/CAMQsgbSoR3Smw_zHrBW%3DL4OSYgtuk1LUo71OY7bCdFAybA5JoQ%40mail.gmail.com.

Ilya Kazakevich

unread,
Sep 23, 2019, 2:42:26 PM9/23/19
to jup...@googlegroups.com
Thank you, Jason.
It is clear now.

Reply all
Reply to author
Forward
0 new messages