1

I'd like to get the values of the slider widgets within some loop. However, I would like these to update in real time.

For example see below. In the code pictured, I initialise some sliders, then run the loop below. Whilst the loop is running I move the sliders around. The printed values from the loop do not change from the initial value. When I execute the last cell, the updated slider values are shown.

enter image description here

3
  • When you run the for loop cell, the kernel will be busy until the loop is over. I believe that sliding the slider will effectively change w only when the loop cell finishes running. Commented Mar 21, 2018 at 14:14
  • 1
    Check asynchronous widgets. Commented Mar 21, 2018 at 14:16
  • Thanks Fabio, I saw this but, seeing as I didn't want the loop to wait for input (I'd just like it to check what it is every second) I thought it wasn't relevant. I will check the example again. Commented Mar 21, 2018 at 14:31

1 Answer 1

1

Here's a solution inspired by the last example in asyncronous widgets (as suggested by @Fabio Perez):

import threading
from IPython.display import display
import ipywidgets as widgets
def f(a, b):
    return

w = interactive(f, a=10, b=20)

def work(w):
    for ii in range(10):
        time.sleep(1)
        print(w.kwargs, w.result)

thread = threading.Thread(target=work, args=(w,))
display(w)
thread.start()

This starts a separate thread which checks the values of the widgets.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, the whole extensions thing is different for jupyter lab as far as I know

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.