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

We should save the (minimal) widget state in the notebook file by default #3108

Open
maartenbreddels opened this issue Feb 9, 2021 · 7 comments · May be fixed by #3114
Open

We should save the (minimal) widget state in the notebook file by default #3108

maartenbreddels opened this issue Feb 9, 2021 · 7 comments · May be fixed by #3114

Comments

@maartenbreddels
Copy link
Member

Problem

People just want to save a notebook with widgets, and the state should be embedded, they by default should not have to worry about saving the widget state, nor do they want the state of 'stale' (unused) widgets in the notebook output.

Proposed Solution

Similar to what we do on the Python side in

def _get_recursive_state(widget, store=None, drop_defaults=False):
we should simply start from all visible widgets, and collect all children, and children of children etc, till we have a consistent (small) state. By default we should store the widget state, unless the user disables it (because saving can be slow).

Maybe there are edge cases where we cannot detect the children, to protect for that we should have a method in WidgetModel to override finding the children, but I think in 99.99% I can find them.

Related #2598

cc @martinRenou

@maartenbreddels maartenbreddels changed the title We should save the (minimal) widget state in notebook by default We should save the (minimal) widget state in the notebook file by default Feb 9, 2021
@vidartf
Copy link
Member

vidartf commented Feb 10, 2021

One corner case at least: If you use traitlets.link, you will only be able to find the dependency between two widgets on the Python side, and not on the JS side. OTOH, this link will only be significant when you have a live kernel, so..

@maartenbreddels
Copy link
Member Author

That is a good point, that means we cannot 'prune' (close) the seemingly stale widgets, since a live kernel can always include hidden connections.

@stevejpurves
Copy link
Contributor

@maartenbreddels is this related to #3007 where in jupyter lab, if we set the "automatically save state" option, then the notebook size balloons as state always seems to be appended?

@maartenbreddels
Copy link
Member Author

@stevejpurves indeed, see #3114 (comment)

@blois
Copy link
Contributor

blois commented Oct 1, 2021

@vidartf widgets.jslink can still be useful in cases when disconnected from the kernel- I'm wondering if would be possible to structure the implementation to be more of a bidirectional link from widget A to widget B, so it would appear as a dependency of either widget A or widget B.

@maartenbreddels
Copy link
Member Author

This PR does pick up jslink, btw.

@J-Rojas
Copy link

J-Rojas commented Jun 23, 2022

This PR helps me understand how to workaround this for my widget library, thanks for pushing this. I can use what you have here to patch my widget library in the meantime. Any chance this will ever be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants