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
Contributor

maartenbreddels commented Oct 16, 2018

Rebase of #779 which is a followup of #760

@maartenbreddels maartenbreddels force-pushed the maartenbreddels:widget_state branch 2 times, most recently from b161eb0 to 3784814 Oct 16, 2018
@maartenbreddels

This comment has been minimized.

Copy link
Contributor Author

maartenbreddels commented Oct 29, 2018

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor Author

maartenbreddels commented Nov 29, 2018

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

This comment has been minimized.

Copy link
Contributor

mgeier commented Nov 29, 2018

Yes exactly, that's the idea!

@maartenbreddels maartenbreddels force-pushed the maartenbreddels:widget_state branch from a6b9e2b to d3f60ac Nov 30, 2018
@maartenbreddels

This comment has been minimized.

Copy link
Contributor Author

maartenbreddels commented Nov 30, 2018

I think this branch is ready for review/merge

@mgeier

This comment has been minimized.

Copy link
Contributor

mgeier commented Jan 14, 2019

Can someone please review this?

@MSeal

This comment has been minimized.

Copy link
Collaborator

MSeal commented Feb 10, 2019

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

@mgeier

This comment has been minimized.

Copy link
Contributor

mgeier commented Mar 12, 2019

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

@MSeal

This comment has been minimized.

Copy link
Collaborator

MSeal commented Mar 12, 2019

@maartenbreddels maartenbreddels force-pushed the maartenbreddels:widget_state branch from abb2e49 to 9877c9e Mar 22, 2019
@maartenbreddels

This comment has been minimized.

Copy link
Contributor Author

maartenbreddels commented Mar 22, 2019

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

This comment has been minimized.

Copy link
Collaborator

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

This comment has been minimized.

Copy link
Contributor Author

maartenbreddels commented Mar 24, 2019

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

This comment has been minimized.

Copy link
Collaborator

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

This comment has been minimized.

Copy link
Contributor Author

maartenbreddels commented Mar 25, 2019

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

@MSeal

This comment has been minimized.

Copy link
Collaborator

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.

@MSeal
MSeal approved these changes Mar 27, 2019
Copy link
Collaborator

MSeal left a comment

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

This comment has been minimized.

Copy link
Contributor Author

maartenbreddels commented Mar 27, 2019

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

@MSeal MSeal merged commit 1fc3968 into jupyter:master Mar 27, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@maartenbreddels

This comment has been minimized.

Copy link
Contributor Author

maartenbreddels commented Mar 27, 2019

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

@maartenbreddels maartenbreddels deleted the maartenbreddels:widget_state branch Mar 27, 2019
@MSeal

This comment has been minimized.

Copy link
Collaborator

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

This comment has been minimized.

Copy link
Collaborator

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

This comment has been minimized.

Copy link
Contributor Author

maartenbreddels commented Apr 4, 2019

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

This comment has been minimized.

Copy link
Collaborator

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

This comment has been minimized.

Copy link
Contributor Author

maartenbreddels commented Apr 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.