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

Update widget menu items in classic Notebook #2012

Closed
wants to merge 1 commit into from

Conversation

jasongrout
Copy link
Member

@jasongrout jasongrout commented Mar 22, 2018

Fixes #1866

This changes the menu items to:

Close All Widgets
----------------
Save Widgets to Notebook
----------------
Download Widget State
Export Widgets to HTML

@jasongrout
Copy link
Member Author

CC @ricklupton

@SylvainCorlay
Copy link
Member

SylvainCorlay commented Mar 22, 2018

From in-person discussion:

The widget manager should listen to the clear_all_outputs event and

  • delete the widget notebook metadata.
  • close the views.

@jasongrout
Copy link
Member Author

jasongrout commented Mar 22, 2018

close the views.

The views should already be deleted when they are removed from the page. We don't want to close the widget (i.e., the model) since we may display it again.

@jasongrout
Copy link
Member Author

The widget manager should listen to the clear_all_outputs event and

Clearing all output does not generate an event, so that would need to be added to the notebook first:

https://github.com/jupyter/notebook/blob/2aac713937c0487dd2193c85a69f02e9556421fe/notebook/static/notebook/js/notebook.js#L2028

@vidartf
Copy link
Member

vidartf commented Mar 23, 2018

We don't want to close the widget (i.e., the model) since we may display it again.

What about for clearing all outputs and restarting the kernel? Is this a separate event?

@jasongrout
Copy link
Member Author

@jasongrout
Copy link
Member Author

So...moving forward with this - is this PR enough of an improvement to merge, or does it muddle things further and should be reconsidered before merging?

@jasongrout
Copy link
Member Author

Actually, let's take a step back and see if we also want to implement #1632 here too.

It looks like there are appropriate hooks in the classic notebook:

https://github.com/jupyter/notebook/blob/2aac713937c0487dd2193c85a69f02e9556421fe/notebook/static/notebook/js/notebook.js#L2729

There is an event that the notebook triggers before saving - perhaps in the widgets menu we have a setting (i.e., menu item with toggle checkmark) that automatically saves the widget state when you save the notebook.

@jasongrout
Copy link
Member Author

(I'm not sure if the jlab notebook has such hooks, but we don't have a widget menu in jlab anyway)

@jasongrout
Copy link
Member Author

jasongrout commented Mar 28, 2018

Okay everyone, how about this?

Close All Widgets
----------------
[ ] Do Not Save Widgets when Saving Notebook
[ ] Save Live Widgets when Saving Notebook
[ ] Save All Widgets when Saving Notebook
----------------
Download Widget State
Export Widgets to HTML

The three Save options make sure that one is selected between them. The setting is saved with the notebook. Saving all widgets saves all widget state with the notebook (including possibly widgets from previous kernels or state that was loaded from the notebook).

Toggling this option would not also save the notebook immediately, but would just set up things so that when the notebook is saved, the state is saved.

@ricklupton
Copy link

Hi Jason, thanks for keeping on with this!

I like the idea of having a toggle to save widgets along with the notebook, but I'm not sure about the live/all distinction.

Does "live" mean "model connected to a kernel" or "model connected to a visible view"? I'm assuming the first in what I write below.

In my case I think I would have to frequently toggle between the two.

  1. I open a notebook with save widgets to fix a typo in a markdown cell. I don't want to rerun everything so I have to remember to switch the toggle to "save all", as there are no live widgets, otherwise I'll accidentally end up with a notebook without widgets -- I guess even if it is autosaved.

  2. I have a new version of the widget that I want to update the notebook to use. I have to either "clear all" before starting (which is fine) or remember to switch the toggle to "save live", otherwise I'll end up with outdated state in the notebook.

So in this case it would be best to always leave it as "save all". But maybe there are other uses when you do want to "save live" every time you open the notebook?

@jasongrout
Copy link
Member Author

So in this case it would be best to always leave it as "save all". But maybe there are other uses when you do want to "save live" every time you open the notebook?

I think if your typical workflow is to open a notebook from scratch, run the cells, and save, the "save live" version is what you would usually want - it erases the previous state, and you don't have to remember to run "clear all".

@vidartf
Copy link
Member

vidartf commented Mar 28, 2018

I open a notebook with save widgets to fix a typo in a markdown cell. [...]

When opening a notebook with stored widgets, it recreates the widgets (i.e. opens them in the kernel), so these will be live. One could possibly imagine a race condition here, where the widgets are slow to re-open, and save request happens quickly. We would have to make sure that this was handled correctly (wait for promises to resolve, then save?) or warned about.

@jasongrout jasongrout modified the milestones: 7.2, 7.3 Mar 29, 2018
@jasongrout
Copy link
Member Author

It sounds like we need to continue the discussion here, so bumping to 7.3.

@thomasaarholt
Copy link

Since it hasn't been explicitly made clear here, I'd like to add the desire for a default preference setting for whether or not to save the workbooks.

Motivation: I generate a new collection of workbooks with each simulation experiment I do, and it's very useful to be able to look up the the results of analysis within the workbook without having to rerun the code. Currently I am often forgetting to press the save widget state menu item.

@jasongrout jasongrout modified the milestones: 7.3, Minor release Jul 6, 2018
@jasongrout jasongrout modified the milestones: 7.3, Major release Jul 16, 2018
@jasongrout jasongrout added this to the Minor release milestone Jul 16, 2018
@SylvainCorlay
Copy link
Member

@jasongrout do you want to get this in for 7.5?

@jasongrout
Copy link
Member Author

@jasongrout do you want to get this in for 7.5?

No.

@jasongrout
Copy link
Member Author

Since this hasn't been worked on in 2 years, I'm closing this. If someone wants to push it forward, please add a note here and open a new PR.

@jasongrout jasongrout closed this Apr 10, 2020
@lock lock bot added the resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label May 20, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
discussion resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clarify how to fully clean widget state when updating versions
5 participants