Often, coming from the widget.param.watch() historical past, I would use watch=True in pn.bind:
import panel as pn
pn.extension()
def update_value(select_value, slider_value):
value = select_value * slider_value
text.value = value
slider = pn.widgets.IntSlider(value=5, start=1, end=10)
select = pn.widgets.Select(value="⭐", options=["⭐", "🐘"])
text = pn.widgets.StaticText()
pn.bind(update_value, select, slider, watch=True)
pn.Row(slider, select, text).show()
Others mentioned that was an anti-pattern, and shared that I can do this instead:
import panel as pn
pn.extension()
def update_value(select_value, slider_value):
value = select_value * slider_value
return value
slider = pn.widgets.IntSlider(value=5, start=1, end=10)
select = pn.widgets.Select(value="⭐", options=["⭐", "🐘"])
text = pn.widgets.StaticText()
text.value = pn.bind(update_value, select, slider)
pn.Row(slider, select, text).show()
To ideally:
import panel as pn
pn.extension()
def update_value(select_value, slider_value):
value = select_value * slider_value
return value
slider = pn.widgets.IntSlider(value=5, start=1, end=10)
select = pn.widgets.Select(value="⭐", options=["⭐", "🐘"])
text = pn.widgets.StaticText(value=pn.bind(update_value, select, slider))
pn.Row(slider, select, text).show()
I think this should be documented in the docs
https://panel.holoviz.org/how_to/interactivity/bind_component.html
The benefit of doing this is not recreating the object.
Often, coming from the
widget.param.watch()historical past, I would usewatch=Truein pn.bind:Others mentioned that was an anti-pattern, and shared that I can do this instead:
To ideally:
I think this should be documented in the docs
https://panel.holoviz.org/how_to/interactivity/bind_component.html
The benefit of doing this is not recreating the object.