How to update an IntSlider from "inside" the function decorated by interact()?
See original GitHub issueI want to visualize a signal’s channel (signal is has dimension (n_samples, n_channels)) using interact, but before retrieving it I don’t know how many channels it will have. Is there a way I can dynamically update the channel slider max value with the n_channels information?
def foo(index, channel):
signal = get_signal(S, index)
n_channels = signal.shape[1]
plt.plot(signal[:,channel])
plt.show()
interact(foo, index=(0,n_sessions-1), channel=(1,10))
I tried defining an enclosed function like:
def foo(index):
def foo2(channel):
plt.plot(signal[:,channel])
plt.show()
signal = get_signal(S, index)
n_channels = signal.shape[1]
interact(foo2, channel=(0,n_channels-1))
interact(foo, index=(0,n_sessions-1))
But this way, when I change the index slider, it creates a new interact output below the old one (I tried using close() and clear_output() but it didn’t work)
I’ve also tried using ipywidgets observe but couldn’t work it out.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Implement a "reset" button when using @interact decorator in ...
Does anybody know how to send to the scope of the decorated function a reference to the original widget objects? I'll be accepting...
Read more >Using Interact — Jupyter Widgets 7.7.0 documentation
The interact function ( ipywidgets.interact ) automatically creates user interface (UI) controls for exploring code and data interactively. It is the easiest ...
Read more >Use interact decorator with figurewidget in Python/v3 - Plotly
This function is decorated with the interact decorator from the ipywidgets package. The decorator parameters are used to specify the ranges of parameters ......
Read more >Jupyter Interactive Widget Ecosystem Tutorial | SciPy 2020
Jupyter widgets are powerful tools for building user interfaces with graphical controls such as sliders and text boxes inside a Jupyter ...
Read more >Decorators with parameters in Python - GeeksforGeeks
Difficulty Level : Hard; Last Updated : 17 Nov, 2021 ... Inside decorator Inside inner function Decorated the function Inside actual function.
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

Can you try using the newest beta of 7.0? This should work:
One final possibility, though it is a bit rough around the edges, and may break in the future if we change the order of controls returned by
interactive: