Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmatically setting slider widget values causes visual desync #2708

Open
tokotchd opened this issue Sep 2, 2021 · 2 comments
Open

Programmatically setting slider widget values causes visual desync #2708

tokotchd opened this issue Sep 2, 2021 · 2 comments
Labels
type: bug Something isn't correct or isn't working

Comments

@tokotchd
Copy link

tokotchd commented Sep 2, 2021

ALL software version info

Panel==0.12.1

Description of expected behavior and the observed behavior

Setting the value of a slider widget programmatically should change both the internal and UI values.
Currently, only the UI value is changed until you interact with each slider again, at which point that internal value updates to the new position.

Complete, minimal, self-contained example code that reproduces the issue

import panel as pn
from panel.template.material import MaterialDefaultTheme

material = pn.template.MaterialTemplate(title="Test", theme=MaterialDefaultTheme)
slider_1 = pn.widgets.IntSlider(name='slider_1', start=1, end=100, value=10)
slider_2 = pn.widgets.IntSlider(name='slider_2', start=1, end=100, value=30)
slider_3 = pn.widgets.IntSlider(name='slider_3', start=1, end=100, value=50)
slider_4 = pn.widgets.IntSlider(name='slider_4', start=1, end=100, value=70)
slider_5 = pn.widgets.IntSlider(name='slider_5', start=1, end=100, value=90)
reset_button = pn.widgets.Button(name='Reset Values')

@pn.depends(
    slider_1.param.value_throttled, 
    slider_2.param.value_throttled, 
    slider_3.param.value_throttled, 
    slider_4.param.value_throttled, 
    slider_5.param.value_throttled, 
)
def test_call(test1, test2, test3, test4, test5):
    return test1, test2, test3, test4, test5

def reset_sliders(event):
    slider_1.value = 10
    slider_2.value = 30
    slider_3.value = 50
    slider_4.value = 70
    slider_5.value = 90
reset_button.on_click(reset_sliders)

material.sidebar.append(slider_1)
material.sidebar.append(slider_2)
material.sidebar.append(slider_3)
material.sidebar.append(slider_4)
material.sidebar.append(slider_5)
material.sidebar.append(reset_button)

material.main.append(pn.Column(test_call))
material.servable()

Screenshots or screencasts of the bug in action

image
Start State
image
Random Slider values
image
Reset button is pressed, sliders show correct values, but programmatic values seen by test_call are not updated
image
Clicking on slider 5 updated the slider 5 value seen in test_call but the others remain out of sync.

@hoxbro
Copy link
Member

hoxbro commented Sep 3, 2021

You can get this to work by changing the test_call to be depending on value instead of value_throttled:

@pn.depends(
    slider_1.param.value,
    slider_2.param.value,
    slider_3.param.value,
    slider_4.param.value,
    slider_5.param.value,
)
def test_call(test1, test2, test3, test4, test5):
    return test1, test2, test3, test4, test5

If you want all the sliders to be throttled I would set pn.config.throttled =True after the imports.

@tokotchd
Copy link
Author

tokotchd commented Sep 3, 2021

Thank you for the concise and hasty reply.

Both parts of what you said are true:
This expected behavior of the reset button does not occur when using .value
Using Pn.config.throttled = true allowed us to keep the desired throttle behavior and achieve intended behavior with the reset button.

Thanks!

@philippjfr philippjfr added the type: bug Something isn't correct or isn't working label Sep 5, 2021
@philippjfr philippjfr added this to the 0.12.2 milestone Sep 5, 2021
@philippjfr philippjfr modified the milestones: 0.12.2, v0.12.x Sep 20, 2021
@philippjfr philippjfr modified the milestones: v0.12.x, v0.13.0 Jan 3, 2022
@philippjfr philippjfr modified the milestones: v0.13.0, next Mar 28, 2022
@philippjfr philippjfr removed this from the next milestone Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

No branches or pull requests

3 participants