Open amine-aboufirass opened 4 months ago
This is a temporary solution I found, but it introduces unnecessary complexity in my opinion:
import ipywidgets as widgets
from IPython.display import display, clear_output
sample_data = {
"A": [1,4,5,7],
"B": [123, 452, 546],
"C": [-23, 23,34, 342, ]
}
dropdown = widgets.Dropdown(options=["A", "B", "C"], description="Value")
output = widgets.Output()
label = widgets.Label(value="test")
def update_label(change):
label.value = str(change['new'])
def update(change):
with output:
clear_output(wait=True)
slider = widgets.SelectionSlider(options=sample_data[dropdown.value], description='Slider')
label.value = str(slider.value)
slider.observe(update_label, 'value')
display(slider)
dropdown.observe(update, "value")
display(dropdown, output, label)
update(None) # To display the initial slider
@jdfreder Not sure if you're the right person for this but it would be great to get confirmation that this is indeed a bug or whether I'm doing something wrong here. I've already tried to discuss this seemingly major issue at the discourse page but didn't get much response. Thanks for your consideration.
Description
Resetting options for a
SelectionSlider
in an update handler won't properly update its value. This seems to occur only when the length of the new option list differs from the length of the old option list.Reproduce
Expected behavior
I expected the slider to jump back to the first value of the option set for b which is 123. In other words, all the way to the right.
Context
Troubleshoot Output
Command Line Output
Browser Output
If using JupyterLab
Installed Labextensions