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

Widget #29

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Widget #29

wants to merge 5 commits into from

Conversation

aazuspan
Copy link
Owner

@aazuspan aazuspan commented Jul 17, 2023

This is a rough draft implementation of async widget reprs (#21). Still need to do some cleanup and take a closer look at compatibility.

To test the Colab demo notebook with async widgets, just pip install this branch:

pip install git+https://github.com/aazuspan/eerepr.git@widget

Compatibility

  • VS Code - Tested locally with 1.79.2
  • ⚠️ Jupyter Lab - Working via Planetary Computer and Binder, non-functional locally.
  • ⚠️ Jupyter Classic - Currently broken
  • ❌ Colab - Probably impossible to work asynchronously because Colab ignores DOM updates from delayed threads. May just need to run synchronously in Colab.

Other Considerations

Widget state

With pure HTML widgets, any static site that supported embedded CSS and JS (e.g. the docs and nbviewer) would render reprs correctly with collapsing functionality. As widgets, I think I will need to explicitly save widget state in order for them to render. Not a dealbreaker, but something to keep in mind. The upside is that notebook files won't get huge due to large reprs unless users intentionally save widget state.

Browser refresh

After installing anywidget, the browser typically (always?) needs to be refreshed to avoid JS errors.

@aazuspan aazuspan added the enhancement New feature or request label Jul 17, 2023
@aazuspan aazuspan self-assigned this Jul 17, 2023
@aazuspan
Copy link
Owner Author

aazuspan commented Jul 17, 2023

Colab

Widgets stay in a loading state indefinitely until you re-execute them. At that point, they display correctly. This suggests the thread responsible for fetching data and updating the widget is fetching the data (caching it for the second call), but not updating the widget.

This StackOverflow answer confirms that this is an issue with how Colab handles threads:

The issue here is that the main thread is not waiting for the created threads to end. After the main thread is done, Google Colab does not seem to wait for the other threads to end, and so the output they produce never reaches the main console

Their solution of using Thread.join works, but removes all benefits of async execution. This follow-up question points that out, but has no responses. It's looking like this is probably an unavoidable implementation detail in Colab, so we may just need to run synchronously in Colab environments.

@aazuspan
Copy link
Owner Author

aazuspan commented Jul 22, 2023

Jupyter Classic

Running notebook server 6.5.4 locally. anywidget is non-functional with browser error Failed to load model class 'AnyModel' from module 'anywidget'.

Possibly related console error: The resource from “http://localhost:8888/static/anywidget.js?v=20230721235015” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff)

This is similar to an error that I see when first installing in Jupyter Lab, but refreshing the browser isn't fixing this case.

@manzt
Copy link

manzt commented Feb 28, 2024

Hi, maintainer of anywidget here 👋

After installing anywidget, the browser typically (always?) needs to be refreshed to avoid JS errors.

Custom widgets (which the anywidget package is) must be installed before starting juypter/jupyterlab. I'm not sure if that was your issue, but running !pip install or %pip install only makes the Python part of the widget discoverable.

Happy to help trouble shoot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants