Dynamic Widget Values#
Download this notebook from GitHub (right-click to download).
import panel as pn
pn.extension(sizing_mode="stretch_width")
This example demonstrates how to control one set of widgets with another set of widgets, such as when the value of one widget changes the allowable values of another. Here the title_widget
and value_widget
control the title and ranges of the other set of widgets, respectively.
title_widget = pn.widgets.TextInput(name='This controls labels', value='LABEL TEXT')
value_widget = pn.widgets.IntSlider(name='This controls values', start=0, end=10, value=5)
meta_widgets = pn.WidgetBox(
title_widget,
value_widget,
)
widgets = pn.WidgetBox(
pn.widgets.TextInput(),
pn.widgets.Spinner(),
pn.widgets.IntSlider(),
pn.widgets.RangeSlider(),
pn.widgets.FloatSlider(),
)
def update_titles(event):
for w in widgets:
w.name = '%s %s' % (w.__class__.__name__, event.new)
title_widget.param.watch(update_titles, 'value')
title_widget.param.trigger('value')
def update_values(event):
for w in widgets:
if isinstance(w.value, (int, float)):
w.value = event.new
w.end = event.new
value_widget.param.watch(update_values, 'value')
pn.Row(meta_widgets, widgets)
App#
Lets wrap it into nice template that can be served via panel serve dynamic_widget_values.ipynb
pn.template.FastListTemplate(site="Panel", title="Dynamic Widget Labels and Values", sidebar=[meta_widgets], main=["This example demonstrates **how to control one set of widgets with another set of widgets**.", widgets]).servable();
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.
Download this notebook from GitHub (right-click to download).