Callbacks not triggered when using observe
See original GitHub issueHi I have the following problem.
When I use:
import ipywidgets as widgets
toggle = widgets.ToggleButton(description='click me')
def on_click(change):
print(change['new'])
toggle.observe(on_click, 'value')
the callback does not get triggered, but if I use
import ipywidgets as widgets
@interact
def clicked(a=widgets.ToggleButton()):
print(a)
the call back gets triggered.
I am using Jupyter Lab: Jupyter Notebook version: 5.6.0 ipywidgets version: 7.2.1
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Observe callback is not being triggered with Kotlin coroutines ...
I'm new to Android development and trying to understand Coroutines and LiveData from various example projects. I have currently setup a function ...
Read more >ractive.observe() | Docs
Observes the data at a particular keypath. Unless specified otherwise, the callback will be fired immediately, with undefined as oldValue .
Read more >IntersectionObserver.observe() - Web APIs - MDN Web Docs
The IntersectionObserver method observe() adds an element to the set of target elements being watched by the IntersectionObserver .
Read more >5 challenges using Plotly Dash for web apps | Analytics Vidhya
For instance, if the Div defined above does not have explicitly the style property referenced in the Python callback, the Javascript code will...
Read more >Solved: Not getting observeField (or observeFieldScoped) t...
Not getting observeField (or observeFieldScoped) to firing callback ... Trying to mash together two (or three) examples I found, to create a ...
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 FreeTop 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
Top GitHub Comments
You’ll need to use an output widget to capture the printed output: http://ipywidgets.readthedocs.io/en/stable/examples/Output Widget.html.
@vidartf Thanks for your help. That code snippet functions the same in the live notebook on Classic server and JupyterLab: The problem is that it still stores all those
<h3>
HTML elements inside of a dynamic JS widget. If you run your code and export to HTML, you need JS enabled (and some libraries loaded from CDN) to view theArbitrary HTML
text. Try running your cell, exporting to HTML, and doing an ‘Inspect Element’. You’ll just see<script>
tags in the output, and no text.Luckily, I have a found a solution for my problem, using the
display_handler = IPython.display.display("foo", display_id="id")
anddisplay_handler.update()
functionality. Below is the code snippet that works in both JupyterLab and Classic Notebook Server. If you export after running it, you will see the raw<h3>
element in the output cell.It’s a bit hacky updating a global from inside a callback, but it fits my need. I am not sure if anyone else has ran into this issue, but this is the best way to dynamically update output cell HTML of the underlying notebook file asyncronously in both JupyterLab and Classic Notebook Server.