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

Embed widget state in notebook on execute #900

Merged
merged 16 commits into from
Mar 27, 2019

Conversation

maartenbreddels
Copy link
Collaborator

Rebase of #779 which is a followup of #760

@maartenbreddels
Copy link
Collaborator Author

Ok, I don't think these failures are caused by this PR, although the Python 2.7 failure is a big strange. All the other are caused by a different in the output for the notebook with the KeyboardException, which now does not include the parenthesis ().

@mgeier
Copy link
Contributor

mgeier commented Nov 26, 2018

Will this be available in the next release?

It seems to work fine, I also tried it programmatically with ExecutePreprocessor and this also works!

@maartenbreddels
Copy link
Collaborator Author

I really hope so!
I guess with this PR we can have clean notebooks in the repo, and RTD will execute and serve the notebooks including the widgets right?

@mgeier
Copy link
Contributor

mgeier commented Nov 29, 2018

Yes exactly, that's the idea!

@maartenbreddels
Copy link
Collaborator Author

I think this branch is ready for review/merge

@mgeier
Copy link
Contributor

mgeier commented Jan 14, 2019

Can someone please review this?

@MSeal
Copy link
Contributor

MSeal commented Feb 10, 2019

Will take a close look this next week and try it out

@mgeier
Copy link
Contributor

mgeier commented Mar 12, 2019

@MSeal Did you have a chance to have a look?

@MSeal
Copy link
Contributor

MSeal commented Mar 12, 2019 via email

@maartenbreddels
Copy link
Collaborator Author

Added a flag to disable the storing of the widget state, e.g.:

python -m nbconvert ipyvolume.ipynb --execute --stdout --to ipynb --ExecutePreprocessor.store_widget_state=False

@MSeal
Copy link
Contributor

MSeal commented Mar 23, 2019

@maartenbreddels Finally got around to looking at this PR. The code looks good, but I'm struggling to reproduce the UI display despite the metadata being present.

python -m nbconvert TEST.ipynb --to ipynb --execute

produces

nbconvert

despite the fact that the metadata is getting populated:

diff.txt

I tried upgrading jupyter classic, jupyter lab, ipython, etc but I'm not getting the rendering that others were posted in related threads to this PR. Ideas for what might be wrong in my setup to reproduce or what might be going wrong with widget state?

@maartenbreddels
Copy link
Collaborator Author

Do you get a rendering if you simply execute the cells in the notebook? If not, there may be an issue with the installation of ipywidgets, for instance pre notebook 5.3 you had to enable the extension manually.

@MSeal
Copy link
Contributor

MSeal commented Mar 24, 2019

Yes. It renders fine if I execute the cells from classic or lab. I upgraded to latest widgets, ipython, and lab (classic hadn't updated in a while). Maybe I should try some different browser / OS combinations. I am on Ubuntu 17.10 latest Chrome

@maartenbreddels
Copy link
Collaborator Author

I had to click File->'Trust this notebook'

@MSeal
Copy link
Contributor

MSeal commented Mar 26, 2019

Ahh yes, I figured I was missing something silly. Each run of the notebook is requiring me to re-trust the outcome, but that's a separate conversation / thread.

Copy link
Contributor

@MSeal MSeal left a comment

Choose a reason for hiding this comment

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

So this solution is working very well -- I even tested custom %%javascript cell logic and it handled it appropriately as well as a variety and combination of widgets interacting and independently operating.

The one thing we should add is documentation for the widget support (including the trust notebook step) and the scope of the support. For example this makes ipynb -> ipynb translation work for standard widgets. It doesn't support other export formats (we can talk about #901 separately and update docs there-in). And it will default behavior for widgets that rely on user input to widget default states or require python programmatic manipulation of the widget to update on nbconvert runs.

Would you prefer to merge this PR first and then add docs, or add some documentation to this PR before merging? I can probably help, just might be delayed before I can write it and you'll probably do better justice to outlining the level of support.

@maartenbreddels
Copy link
Collaborator Author

Thanks, and yes indeed, I'd rather see this merged first.

@MSeal MSeal merged commit 1fc3968 into jupyter:master Mar 27, 2019
@maartenbreddels
Copy link
Collaborator Author

Thanks, really happy to see this in master, looking forward to the next release!

@maartenbreddels maartenbreddels deleted the widget_state branch March 27, 2019 17:57
@MSeal
Copy link
Contributor

MSeal commented Mar 27, 2019

Thanks for making the PRs. I'll try reading through 901 later this week. Plan is currently to do a release early to mid April after some other changes get finalized.

@MSeal
Copy link
Contributor

MSeal commented Apr 4, 2019

@maartenbreddels Any chance you could add those document requests before we release? It'd help with making the release notes.

@maartenbreddels
Copy link
Collaborator Author

I propose the following at the end of execute_api.rst:


Widget state
------------

If your notebook contains any `Jupyter Widgets <https://github.com/jupyter-widgets/ipywidgets/>`_,
the state of all the widgets can be stored in the notebook's metadata (starting from nbconvert 5.5).
This allows rendering of the live widgets on for instance nbviewer, or when converting to html.
We can tell nbconvert to not store the state using the `store_widget_state` argument::

    jupyter nbconvert --ExecutePreprocessor.store_widget_state=False --to notebook --execute mynotebook.ipynb

Feel free to copy/paste and/or modify if you want (I think it is less work than opening a PR for this, unless you disagree)

@MSeal
Copy link
Contributor

MSeal commented Apr 4, 2019

I'll probably open a PR anyway so it's more visible -- but that helps. The only additions I think we should include might be:

This widget rendering is not performed against a browser during execution, so only widget default 
states or states manipulated via user code will be calculated during execution. `%%javascript` cells 
will execute upon notebook rendering, enabling complex interactions to function as expected when 
viewed by a UI.

If you can't view widget results after execution, you may need to select `Trust Notebook` under the 
`File` menu.

Thoughts or rewording?

@maartenbreddels
Copy link
Collaborator Author

maartenbreddels commented Apr 4, 2019 via email

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.

4 participants