0

Is it possible using Panel to temporarily disable the automatic linking of widgets while setting the values of multiple widgets?

The code below shows a simplified example of my situation, in reality I have much more widgets. The key issue is that I have a Select widget, that links to some pre-configured values in a dictionary, and on-change I want it to update all other widgets.

All of this works fine, except that when the first widget gets a new value using this, it instantly triggers a redraw of the entire plot before all other widgets are also updated. Not only gives this a unnecessary flickering effect (updating the plot n_widgets times instead of once), some intermediate values also cause the plot to show some "wild" results because the intermediate values cause unrealistic combinations.

dropdown_box = pn.widgets.Select(options=selection_options, name="selection")
slider1 = pn.widgets.FloatSlider(start=0, end=1, step=0.01, value=0.5, name="slider1")
slider2 = pn.widgets.FloatSlider(start=0, end=1, step=0.01, value=0.5, name="slider2")
slider3 = pn.widgets.FloatSlider(start=0, end=1, step=0.01, value=0.5, name="slider3")
slider4 = pn.widgets.FloatSlider(start=0, end=1, step=0.01, value=0.5, name="slider4")

@pn.depends(dropdown_box.param.value, watch=True)
def update_cfg(selection):

    val1, val2, val3, val4 = lookup_cfg[selection] # lookup_cfg

    # < some intermediate stuff >

    slider1.value = val1
    slider2.value = val2
    slider3.value = val3
    slider4.value = val4

my_plot = hv.DynamicMap(pn.bind(
    create_plot,
    param1=slider1, 
    param2=slider2, 
    param3=slider3, 
    param4=slider4,
    **plot_kwargs,
))

Even assigning all slider.value's on the same line still causes the widgets to be updated one-by-one, so that's not a workaround. I'm wondering if there's something along the lines of the progress spinner that actually blocks any updates/triggering until "released" so I can change many widgets while only updating the plot once?

Something along the lines of:

with pn.block_updates():
    slider1.value = val1
    slider2.value = val2
    slider3.value = val3
    slider4.value = val4

I also tried disabling the widgets up front (slider.disabled = True), but that only prevent the user from interacting with them.

I could make a fully working example with some toy data if the code above is unclear.

Rutger Kassies
  • 61,630
  • 17
  • 112
  • 97

0 Answers0