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 the case when one widget model fails to be created #935

Conversation

martinRenou
Copy link
Member

@martinRenou martinRenou commented Sep 1, 2021

Code changes

Handle the case when one widget model fails to be created, so that other widgets in the page can be rendered anyway.

This behavior is closer to other front-ends like JupyterLab.

Reproduce

The following Notebook code can reproduce the issue. Here the grid model is invalid and throws an error when being created.

Due to this error, the slider could not be rendered.

# Cell 1
from ipywidgets import Tab, IntSlider

tab = Tab()

import pandas as pd
from ipydatagrid import DataGrid, TextRenderer, VegaExpr

df = pd.DataFrame(
    {
        "column 1": [{"key": 11}, ["berry", "apple", "cherry"]],
        "column 2": [["berry", "berry", "cherry"], {"key": 10}],
    }
)

renderer = TextRenderer(
    background_color=VegaExpr(
        "cell.value[1] == 'berry' && cell.metadata.data['column 1']['key'] == 11 ? 'limegreen' # : 'pink'"
    )
)

tab.children = [DataGrid(
    df,
    layout={"height": "100px"},
    base_column_size=150,
    default_renderer=renderer,
), IntSlider()]
tab

# Cell 2

print('hey')

# Cell 3
IntSlider()

Result before this PR (the slider cannot render):
voilaold

Result after this PR (the slider can render):
voilanew

@jtpio jtpio added the bug Something isn't working label Sep 1, 2021
@jtpio jtpio added this to the 0.2.x milestone Sep 1, 2021
@jtpio
Copy link
Member

jtpio commented Sep 1, 2021

Thanks!

This behavior is closer to other front-ends like JupyterLab.

This change seems to correspond to what the JupyterLab manager does: https://github.com/jupyter-widgets/ipywidgets/blob/29c29bf70655b49f0f50230dbeb2e01a15ce55cd/jupyterlab_widgets/src/manager.ts#L114-L118

Copy link
Member

@jtpio jtpio left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@jtpio jtpio merged commit d0b2e82 into voila-dashboards:master Sep 1, 2021
@martinRenou martinRenou deleted the handle_widget_model_creation_error branch September 1, 2021 09:33
@martinRenou
Copy link
Member Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants