question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

display_data and update_display_data in widget output not working as expected

See original GitHub issue

I am trying to update the output after a slider callback (see attached GIF). Other displays change as expected, but the one below the slider does not update.

peek 2017-11-30 17-46

# In[1]:
ip = get_ipython()
import ipywidgets as widgets
def display_with_id(obj, display_id=None, update=False):
    iopub = ip.kernel.iopub_socket
    session = ip.kernel.session
    data, md = ip.display_formatter.format(obj)
    transient = {'display_id': display_id}
    content = {'data': data, 'metadata': md, 'transient': transient}
    if display_id is None: content.pop('transient')  # make display_id option
    msg_type = 'update_display_data' if update else 'display_data'
    session.send(iopub, msg_type, content, parent=ip.parent_header)
display = display_with_id
# In[2]:
display('initial display', 'some_destination')
# In[11]:
display('spoiler alert: output updated in both', 'some_destination')
# In[4]:
display('no output here, update above', 'some_destination', update=True)
# In[5]:
w = widgets.IntSlider()
# In[6]:
display(w)
# In[7]:
w.value = 13
# In[8]:
first_disp = True
# In[9]:
def value_change(change):
    global first_disp
    if first_disp:
        display('ABCDEFG', 'some_destination', update=False)
        first_disp = False
    else:
        display("Not first anymore!", "some_destination", update=True)
# In[10]:
w.observe(value_change, names='value')

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jasongroutcommented, Nov 30, 2017

Thanks. It does look like something is not quite right. We’ll check into it. A guess is that for some reason, the display region produced as a result of a widget action is not getting registered with the list of displays with that id.

FYI, you can also use an output widget for this sort of thing:

w = widgets.IntSlider()
out = widgets.Output()

display(w)
display(out)

def value_change(change):
    with out:
        print('new output')
w.observe(value_change, 'value')

See also https://ipywidgets.readthedocs.io/en/stable/examples/Widget List.html#Output

0reactions
wolfvcommented, Dec 1, 2017

thanks a lot for looking into this. I can currently work around it by creating a “widget-independent” display before creating the widget, but of course having the display connected to the widget would be nicer!

cheers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

After Android 12 update .Display Data usage in notification ...
Display Data usage in notification drawer not showing; Was this a problem in ... Expected behavior: Any other comments: OnePlus pls fix this...
Read more >
python - Jupyter Output widget not clearing
You are using append_display_data() and so it is being appended? Even if it is getting cleared showing in ouput. That's my guess at...
Read more >
Nbdev v2 & Jupyter Widgets
I am trying to get nbdev v2 to generate docs that include Jupyter widgets. Is this expected to work? The Quarto docs show...
Read more >
Output widgets: leveraging Jupyter's display system - IPyWidgets
You are not reading the most recent version of this documentation. ... You can also append output directly to an output widget, or...
Read more >
Why does the Output context manager not show ...
If I use the append_stdout method instead, it does work (however that ... as per the title I'm not seeing expected output in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found