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

How to retain widget state in output notebooks? #400

Open
choldgraf opened this issue Jul 15, 2019 · 5 comments
Open

How to retain widget state in output notebooks? #400

choldgraf opened this issue Jul 15, 2019 · 5 comments

Comments

@choldgraf
Copy link
Contributor

I'm trying to use papermill to generate report notebooks that include ipywidgets in their outputs. When I use papermill to build these, the widget state doesn't seem to be included in the output notebook. I've tried playing around with this a bit and have found the following things:

  • If I run the notebook and create the widgets interactively, then use nbconvert to convert to a different notebook (e.g. jupyter-nbconvert --to notebook mynotebook.ipynb) then the widgets display correctly
  • If I run papermill on the notebook, then the widget is not displayed correctly (it just displays the text representation of the widgets)
  • If I use --execute to the nbconvert command, it also does not display correctly (jupyter-nbconvert --to notebook mynotebook.ipynb --execute).

So I guess this is a problem with executing the notebook rather than simply converting the output of a pre-existing notebook. The final point above makes me suspect that this is a problem at the nbconvert level rather than the papermill level, but I'd be curious if folks have run into this here and if there are any workarounds.

It sounds like @maartenbreddels and @jasongrout worked on retaining widget state in jupyter/nbconvert#900 - perhaps they've got thoughts on achieving the same thing after executing the cells in a notebook

@MSeal
Copy link
Member

MSeal commented Jul 16, 2019

@choldgraf Have you clicked "Trust Notebook" after executing (bottom of https://nbconvert.readthedocs.io/en/latest/execute_api.html#widget-state highlights this)?

@choldgraf
Copy link
Contributor Author

Hmm - I think there might be multiple things going on there:

You are correct that when I create a simple widget in a notebook, then use papermill to create a new notebook, then "trust" the notebook and reload the page, that the widget now shows up.

However, this sometimes doesn't happen and I'm not sure why. For a more complex example, for this notebook:

https://github.com/choldgraf/jupyter-activity-snapshot/blob/master/reports/2019-05-17_2019-07-16.ipynb

The method above doesn't work - if I "trust" the output notebook, I still get errors in rendering the widgets.

Moreover when this is rendered on nbviewer (which I don't think should be affected by "trust notebook" or not) the widgets are just blank:

https://nbviewer.jupyter.org/github/choldgraf/jupyter-activity-snapshot/blob/master/reports/2019-05-17_2019-07-16.ipynb#A-list-of-recent-issues

So...I guess maybe this is some kind of interaction between ipywidgets, altair, and nbconvert?

@MSeal
Copy link
Member

MSeal commented Jul 16, 2019

It does sound like an oddity with those libraries. Might be worth posting to altair and/or ipython issues. I will try to take a look this weekend at the example more closely for if there's something odd with nbconvert propagating the payload, but I suspect it's unlikely to be a problem there.

@choldgraf
Copy link
Contributor Author

that sounds good - I tried a bunch of combinations of plotting w/ altair and various tabbed widget outputs with ipywidgets, and couldn't get it to reproduce outside of the context of the mega notebook I linked above.

If you don't think there's a path forward on this, feel free to close this one, as you say I doubt that this is a strictly papermill (or nbconvert) fix

@tgpfeiffer
Copy link

If I run papermill on the notebook, then the widget is not displayed correctly (it just displays the text representation of the widgets)

I have the same issue. The papermill changelog says that "ipywidgets are now supported" from version 1.0.0 but how would I trigger that from the command line? Is it possible to just add a parameter to papermill in.ipynb out.ipynb to get the widgets in the output notebook, or do I need to call papermill programmatically (and how)? Thanks!

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

No branches or pull requests

3 participants