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

HTMLManager: Support both ipywidgets 7 and 8 models #3932

Merged
merged 7 commits into from
Aug 21, 2024

Conversation

martinRenou
Copy link
Member

@martinRenou martinRenou commented Jul 30, 2024

Currently, the HTML manager brings the jupyter-widgets front-end for ipywidgets 8, disregarding the version stored in the widget model.
This works fine in most cases, as long as the user did not store an ipywidgets 7 model that was making use of removed APIs.

This PR resolves this by lazily loading either the jupyter-widgets front-end for 7 or 8 depending on the version stored in the model. Similar to the approach taken in voila-dashboards/voila#1482

Testing nbconvert output with ipywidgets 7:
Screenshot from 2024-07-30 15-43-30

Testing nbconvert output with ipywidgets 8:
Screenshot from 2024-07-30 15-43-36

Copy link

Binder 👈 Launch a binder notebook on branch martinRenou/ipywidgets/html_manager_7_8

"@jupyter-widgets/controls": "^5.0.9",
"@jupyter-widgets/controls7": "npm:@jupyter-widgets/[email protected]",
Copy link
Member

Choose a reason for hiding this comment

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

👍

@SylvainCorlay
Copy link
Member

I like this solution. It will solve many user's headaches.

@maartenbreddels
Copy link
Member

Nice work! In solara we use a similar trick with the npm alias, but we actually have to build 2 separate managers. I think this is a cleaner solution.

@martinRenou
Copy link
Member Author

Nice work! In solara we use a similar trick with the npm alias, but we actually have to build 2 separate managers. I think this is a cleaner solution.

Oh nice I did not know you tried that in Solara too! Note that we've done something similar in Voila 0.4.x but with just one manager: voila-dashboards/voila@5934c53, it's a bit different from the approach in this PR as it makes use of the lazy loading approach in the widgets register, so the widgets assets will load only upon request.

I tried with latest Voila but things are more complicated there for some reason.

@maartenbreddels
Copy link
Member

In solara (because we run in the same process), we know beforehand at the server what the version of ipywidgets is, which allows for a different strategy.
We also build the final bundle twice using the webpack alias trick:
https://github.com/widgetti/solara/blob/20b2e8012e7683eb38ff62a74a371eb1a052bf41/packages/solara-vuetify-app/webpack.config.js#L95

I don't think you need it here, but both these tricks allow for some fancy building/bundling options.

@martinRenou
Copy link
Member Author

We also build the final bundle twice using the webpack alias trick:
https://github.com/widgetti/solara/blob/20b2e8012e7683eb38ff62a74a371eb1a052bf41/packages/solara-vuetify-app/webpack.config.js#L95

Ah, that trick could probably be useful to me for Voila 0.5.x, I'll have to give it a try. Thanks for sharing!

@martinRenou martinRenou merged commit 73c98f0 into jupyter-widgets:main Aug 21, 2024
20 checks passed
@martinRenou martinRenou deleted the html_manager_7_8 branch August 21, 2024 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants