display_data and update_display_data in widget output not working as expected
See original GitHub issueI 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.
# 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:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
See also https://ipywidgets.readthedocs.io/en/stable/examples/Widget List.html#Output
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!