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

output widget append_display_data does not display widgets #1811

Closed
jasongrout opened this issue Nov 9, 2017 · 10 comments · Fixed by #2021
Closed

output widget append_display_data does not display widgets #1811

jasongrout opened this issue Nov 9, 2017 · 10 comments · Fixed by #2021
Assignees
Labels
resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Milestone

Comments

@jasongrout
Copy link
Member

jasongrout commented Nov 9, 2017

It seems there are some problems either with the output widget append_display_data method (from #1752), or how we display widgets.

from ipywidgets import Output, IntSlider
out = Output(layout={'border': '1px solid black'})
out.append_display_data(IntSlider())
out

should capture the intslider inside of the output widget, but instead we get

screen shot 2017-11-08 at 8 56 40 pm

If I use the output widget as a context manager, it works fine:

from ipywidgets import Output, IntSlider
from IPython.display import display
out = Output(layout={'border': '1px solid black'})
with out:
    display(IntSlider())
out

screen shot 2017-11-08 at 8 58 43 pm

@jasongrout jasongrout added this to the 7.0.x milestone Nov 9, 2017
@jasongrout
Copy link
Member Author

jasongrout commented Nov 9, 2017

From the docs http://ipython.readthedocs.io/en/stable/api/generated/IPython.core.formatters.html:

Prior to IPython 6.1, _ipython_display_ was the only way to display custom mime-types without registering a new Formatter.
IPython 6.1 introduces _repr_mimebundle_ for displaying custom mime-types, so _ipython_display_ should only be used for objects that require unusual display patterns, such as multiple display calls.

We use _ipython_display_, in which we manually call display to display a widget. When we switch to using _repr_mimebundle, I think this issue will resolve itself.

@jasongrout
Copy link
Member Author

IPython 6.1 was released 31 May 2017. I think it will be a while before we can mandate IPython 6.1+ (likely not until ipywidgets 8), so we may just have to live with this for now.

@jasongrout jasongrout modified the milestones: 7.0.x, Future Nov 9, 2017
@jasongrout
Copy link
Member Author

actually, we may be able to register a display using the for_type mechanism instead, until we can move to a simple _repr_mimebundle_: http://ipython.readthedocs.io/en/stable/api/generated/IPython.core.formatters.html#IPython.core.formatters.BaseFormatter.for_type

@GaiYu0
Copy link

GaiYu0 commented Nov 26, 2017

Hi, I am experiencing a similar problem. In my case, the slider widget is displayed properly but the output widget cannot be displayed. Is there any temporary solution?

Thank you very much!

@jasongrout
Copy link
Member Author

@GaiYu0, can you post the code you are using?

@GaiYu0
Copy link

GaiYu0 commented Nov 27, 2017

It turns out that my problem was caused by broken dependencies, which is irrelevant from this issue. Sorry!

@jasongrout
Copy link
Member Author

jasongrout commented Mar 19, 2018

actually, we may be able to register a display using the for_type mechanism instead, until we can move to a simple repr_mimebundle: http://ipython.readthedocs.io/en/stable/api/generated/IPython.core.formatters.html#IPython.core.formatters.BaseFormatter.for_type

This won't work. It looks like registering a for_type handler in the ipython display formatter is equivalent to defining the _ipython_display_ function, so it doesn't get us anything more than we had.

So I'm moving this issue into the Major Release milestone, for when we can require ipython >=6.1 and define a _repr_mimebundle_ method.

@jasongrout jasongrout modified the milestones: 7.2, Major release Mar 19, 2018
@jasongrout
Copy link
Member Author

It looks like IPython 6.1 was released May 31, 2017, so we should probably wait until at least June 2018 to make this change.

@jasongrout
Copy link
Member Author

Perhaps we can put in a check for the ipython version, and use the _repr_mimebundle_ if we are in a version that supports it, and otherwise use (monkeypatch?) our class to have the _ipython_display_ method?

@jasongrout jasongrout modified the milestones: Major release, 7.2 Mar 26, 2018
jasongrout added a commit to jasongrout/ipywidgets that referenced this issue Mar 27, 2018
jasongrout added a commit to jasongrout/ipywidgets that referenced this issue Mar 27, 2018
jasongrout added a commit to jasongrout/ipywidgets that referenced this issue Mar 28, 2018
@jasongrout jasongrout modified the milestones: 7.2, Major release Mar 28, 2018
@vidartf
Copy link
Member

vidartf commented Mar 4, 2019

Note: Python allows you to conditionally declare methods, so no monkey-patching would be needed:

In [1]: class A:
   ...:     if True:
   ...:         def sum(self, a, b):
   ...:             return a + b
   ...:

In [2]: a = A()

In [3]: a.sum(5, 6)
Out[3]: 11

In [4]: class B:
   ...:     if False:
   ...:         def sum(self, a, b):
   ...:             return a + b
   ...:

In [5]: b = B()

In [6]: b.sum(5, 6)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-b0fbaf787c6b> in <module>
----> 1 b.sum(5, 6)

AttributeError: 'B' object has no attribute 'sum'

jasongrout added a commit to jasongrout/ipywidgets that referenced this issue Dec 31, 2019
jasongrout added a commit to jasongrout/ipywidgets that referenced this issue Dec 31, 2019
@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 21, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants