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

ipywidgets cannot be displayed in the SimplifiedOutputArea widget in the kernel-output example #107

Open
yidong72 opened this issue Jul 28, 2020 · 6 comments

Comments

@yidong72
Copy link

I filed the same issue #2926 at the ipywidget repo. No response yet.

I followed the example at
https://github.com/jupyterlab/extension-examples/tree/master/advanced/kernel-output
The ipywidgets can be displayed fine in the notebook cells, but not in the SimpliedOutputArea from @jupyterlab/outputarea created manually. I checked the rendermime, it contains the mimetypes for ipywidgets.
Not sure what I need to do to make it work. Please help. Thanks.

@jtpio
Copy link
Member

jtpio commented Aug 31, 2020

@yidong72 which version of JupyterLab are you using?

Also are there any errors in the browser dev tools console?

@saswatac
Copy link

saswatac commented Mar 9, 2024

i am also seeing this in jupyter lab version 4.0.6. to repro, you can put the code to execute as from ipywidgets import IntSlider; IntSlider(value=10) .

In the jupyterlab main panel, the output is IntSlider(value=10) in plain text. On browser console, I see the error "Exception opening new comm"

@saswatac
Copy link

saswatac commented Nov 6, 2024

Following up on this discussion again. From the debugger on the dev tools, I have identified that the exception opening new comm is -

"Error: Object 'jupyter.widget' not found in registry at .."

The specific message is -

_model_module: "@jupyter-widgets/base"
_model_module_version: "2.0.0"
_model_name: "LayoutModel"
_view_count: null
_view_module: "@jupyter-widgets/base"
_view_module_version: "2.0.0"
_view_name: "LayoutView"

I would expect the basic models to be registered, do I need to somehow register them again in my jupyterlab extension?

@jtpio do you have any suggestions?

@jtpio
Copy link
Member

jtpio commented Nov 6, 2024

Just to double check it's not related to a recent ipywidgets release: would you be able to try with ipywidgets<8.1.3 and jupyterlab-widgets<3.0.11 (jupyterlab-widgets is the extension providing widget support in JupyterLab).

@saswatac
Copy link

saswatac commented Nov 6, 2024

i am using ipywidgets==8.1.1 and jupyterlab-widgets==3.0.9

@saswatac
Copy link

saswatac commented Nov 7, 2024

I was able to make some progress by following the code in https://github.com/jupyter-widgets/ipywidgets/blob/303cae4dc268640a01ce08bf6e22da6c5cd201e4/python/jupyterlab_widgets/src/plugin.ts .

The missing pieces were -

  1. The render mime object has a default renderer for "application/vnd.jupyter.widget-view+json." Instead, we need to hook up the rendermime with a kernel widget manager for the specific kernel so that it registers the kernel's comm target.
rendermime.removeMimeType(WIDGET_VIEW_MIMETYPE);
const manager = new KernelWidgetManager(this._sessionContext.session!.kernel!, rendermime);
rendermime.addFactory(
          {
            safe: true,
            mimeTypes: [WIDGET_VIEW_MIMETYPE],
            createRenderer: (options) => new WidgetRenderer(options, manager)
          },
          -10
        );
  1. the widget manager needs to be registered with all the available widget models.
WIDGET_REGISTRY.forEach((data) => manager!.register(data));
  1. When registering the renderer in 1, option safe should be set to True. otherwise, the text mimetype is always preferred, and widget never gets rendered.

is this the right approach?

I have a follow-up request - for point 2, the WIDGET_REGISTRY list is not exported https://github.com/jupyter-widgets/ipywidgets/blob/303cae4dc268640a01ce08bf6e22da6c5cd201e4/python/jupyterlab_widgets/src/plugin.ts#L62C24-L62C50 . could we export it, or better enhance the IJupyterWidgetRegistry interface to add a method to fetch all the registered widgets?

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

3 participants