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

Handle KernelWidgetManager in the JupyterLab OutputModel #3561

Merged

Conversation

jtpio
Copy link
Member

@jtpio jtpio commented Aug 22, 2022

Investigating an issue in voila-dashboards/voila#846 where using an interactive_output would trigger the following error:

TypeError: Cannot read properties of undefined (reading 'sessionContext')

voila-dashboards/voila#846 uses the JupyterLab packages but with a custom KernelWidgetManager, not a WidgetManager like in the JupyterLab extension. This is because it only has access to a kernel connection, not a document context.

However in its present state, the OutputModel assumes it can access the context from its widget_manager here:

this.widget_manager.context.sessionContext.kernelChanged.connect(

Ideally it should be able to handle both a WidgetManager and KernelWidgetManager or even a LabWidgetManager directly.


For reference the widget_manager assigned to a WidgetModel is declared as any here:

widget_manager: any;

And assigned here:

this.widget_manager = options.widget_manager;

@github-actions
Copy link

Binder 👈 Launch a binder notebook on branch jtpio/ipywidgets/output-model-kernel-widget-manager

@@ -114,7 +117,7 @@ export class OutputModel extends outputBase.OutputModel {
}
}

widget_manager: WidgetManager;
widget_manager: LabWidgetManager;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately changing from a more specialized to a more generic type here looks like a breaking change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking that another approach could be for those defining their own widget manager based on a KernelWidgetManager to also define their own OutputModel and register it.

Although this means duplicating quite a bit of code from ipywidgets and change the handling of the context / kernel.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking that another approach could be for those defining their own widget manager based on a KernelWidgetManager to also define their own OutputModel and register it

Linking to voila-dashboards/voila@3840999 which implements this approach (may be temporary).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately changing from a more specialized to a more generic type here looks like a breaking change.

Having breaking changes and therefore a major version bump on the lab manager isn't necessarily that problematic though.

Copy link
Member

@vidartf vidartf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but will probably require a major version bump of the jupyterlab extension (at least on the JS side), since the typing on the OutputModel changes. That should hopefully not be a big problem though.

@martinRenou martinRenou merged commit 2af0cc4 into jupyter-widgets:master Nov 17, 2022
@martinRenou
Copy link
Member

Thanks!

@jtpio jtpio deleted the output-model-kernel-widget-manager branch November 18, 2022 09:14
@stevejpurves
Copy link
Contributor

This looks like this could have been released in 8.0.x already but the milestone shows 8.1, i'n still seeing an error in 8.0.4 and wanted to check that this was expected?

@jtpio
Copy link
Member Author

jtpio commented Mar 9, 2023

Since this change affects the jupyterlab-widgets Python package only, looks like it should have be available now? The latest release shows December 22, 2022 on PyPI:

image

@jtpio
Copy link
Member Author

jtpio commented Mar 9, 2023

So a quick way to check could be to upgrade to the latest version with python -m pip install -U jupyterlab-widgets

@stevejpurves
Copy link
Contributor

Thanks for the orientation @jtpio - i've just confirmed i'm running that version in jupyterlab and I can see the change in @jupyter-widgets/jupyterlab-manager 5.0.5 👍🏼

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

Successfully merging this pull request may close these issues.

None yet

5 participants