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

Implement Output widget at nbconvert level for interact #91

Merged

Conversation

maartenbreddels
Copy link
Member

As mentioned in #19 and #85 there are some issues with interact. Interact(ion) uses the Output widget a lot, which relies on the frontend to handle display and clear_output differently.

A part of the fix is in jupyter/nbconvert#969 which deals with wait=True, but this only solves part of the issue.

When nbconvert is used to execute the notebook, there is no OutputWidget that can hook into the display mechanism to redirect display and clear_output calls. This custom executor creates a 'fake' Output widget that mirrors this behaviour.

This is to show that it is possible to support interact with voila, I am not sure this is the best solution. Other solution are:

  1. Implement display/clear_output redirects kernel side, in Python this is simply monkey patching display and clear_output and possibly stdout/stderr, but I am not sure this will work with with xeus-python, and similar solutions would be needed for all the other kernels.
  2. Do no use nbconvert for the execution, only start executing once a frontend is connected.

I think the core problem is that interact(ion) relies on the Output widget being connected to the frontend. We could solve some problems by actually modifying Output.ouputs at the kernel side, and never invoke display/clear_output, but directly invoke methods on the Output widget.

If we want to go forward with this approach (which would be the most compatible one), this requires a few more tweaks and a few tests (wait=True for the output widget it no supported)

@maartenbreddels
Copy link
Member Author

While testing found a bug in ipywidgets:
jupyter-widgets/ipywidgets#2351

display_id in the Output widget is not supported yet, and we could do a refactor to do code deduplication with nbconvert's ExecutePreprocessor.

To perform testing we need to use jupyter/nbconvert#900, coverage for execute.py is 100%.

@enryH
Copy link

enryH commented Jul 15, 2019

Could you provide an example? Using

from ipywidgets import interact

def foo(x):
    print(x)

interact(foo, x=(0, 10))

yields as output only

5

without the slider.

@SylvainCorlay
Copy link
Member

@enryH this appears to work. Are you talking about voila or nbconvert?

@enryH
Copy link

enryH commented Jul 15, 2019

@enryH this appears to work. Are you talking about voila or nbconvert?

voila. I did not pay attention and another package set the voila version to 0.0.9... Works just fine in a new env. Thanks anyways for the nice work:)

maartenbreddels added a commit to maartenbreddels/nbclient that referenced this pull request May 26, 2020
maartenbreddels added a commit to maartenbreddels/nbclient that referenced this pull request May 26, 2020
maartenbreddels added a commit to maartenbreddels/nbclient that referenced this pull request May 26, 2020
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.

3 participants