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

feat: when a widget fails, show a fallback error widget #667

Conversation

maartenbreddels
Copy link
Member

Fixes #657
Consider this code:

import ipywidgets as widgets
from traitlets import Unicode

class BadWidget(widgets.DOMWidget):
    _model_module = Unicode('badwidget').tag(sync=True)
    _view_module = Unicode('badwidget').tag(sync=True)
    _view_name = Unicode('DoesNotExist').tag(sync=True)
bad_widget = BadWidget()
widgets.HBox([bad_widget, widgets.Button(description='Hi')])

This would now render to:

image

If the semver is off:

import ipywidgets as widgets
from traitlets import Unicode

class BadVersion(widgets.Button):
    _model_module_version = Unicode('11.0').tag(sync=True)
bad_version = BadVersion()
widgets.HBox([bad_version, widgets.Button(description='Hi')])

You'd see this:
image

And if the widget model name is off:

import ipywidgets as widgets
import ipyvolume as ipv
from traitlets import Unicode

class BadName(ipv.Figure):
    _model_name = Unicode('Fig').tag(sync=True)
bad_name = BadName()
widgets.HBox([bad_name, widgets.Button(description='Hi')])

It renders:

image

So in all of these cases, something gets rendered. The only case that is not handled, is when the view_name is off (difficult to catch)

@maartenbreddels maartenbreddels force-pushed the feat_error_widget_fallback branch from 9187a37 to 75d7c70 Compare August 3, 2020 14:00
@SylvainCorlay
Copy link
Member

cc @jasongrout

@maartenbreddels
Copy link
Member Author

Me might want to have a troubleshoot link in the message. Maybe we should then also have a troubleshoot page at ipywidgets?

Another thing we should consider, is add two methods to the widget manager:

  • loadViewClass (default implementation can call loadClass)
  • loadModelClass (idem)

Since now we do not know when a Model or View needs to be loaded, we cannot create a fallback Model or View.

@maartenbreddels maartenbreddels force-pushed the feat_error_widget_fallback branch from 75d7c70 to 5b43717 Compare August 4, 2020 12:04
@maartenbreddels
Copy link
Member Author

Code is simplified a bit (force pushed)

@maartenbreddels maartenbreddels force-pushed the feat_error_widget_fallback branch from 5b43717 to 85fd9d9 Compare August 5, 2020 13:28
@maartenbreddels
Copy link
Member Author

@SylvainCorlay I think we can merge this, the failure on Travis seems a fluke, and we cannot restart it 🤷

We might want to consider upstreaming this to core jupyter-widgets (working on it), but I think that will take a while.

@SylvainCorlay
Copy link
Member

@maartenbreddels I just rebased your PR and translated the code to AnyScript so that it works with the new typescript codebase.

@SylvainCorlay SylvainCorlay force-pushed the feat_error_widget_fallback branch from 95a63e0 to a4dff1f Compare February 4, 2021 16:45
@SylvainCorlay SylvainCorlay force-pushed the feat_error_widget_fallback branch from a4dff1f to 81706ce Compare February 4, 2021 17:01
@trungleduc
Copy link
Member

Hi @maartenbreddels, I'm working on testing Voila with different types of bugged widgets (#985) so I tried your PR and it works nicely. I think it will be super useful if it can be merged.

@maartenbreddels
Copy link
Member Author

maartenbreddels commented Oct 18, 2021

I think it would be better to work on the upstream version of this jupyter-widgets/ipywidgets#2960
Do you agree?

@martinRenou
Copy link
Member

If we're fast enough, we can maybe squeeze it in ipywidgets 8.0

@trungleduc
Copy link
Member

I think it would be better to work on the upstream version of this jupyter-widgets/ipywidgets#2960 Do you agree?

Indeed, it missed that part, I will try to push it into 8.0

@maartenbreddels
Copy link
Member Author

That would be great!

@trungleduc
Copy link
Member

This feature is added in ipywidgets 8.

@trungleduc trungleduc closed this Aug 4, 2022
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.

Missing nbextensions: we should be more resilient to one widget library missing in the frontend
4 participants