Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
holoviz
GitHub Repository: holoviz/panel
Path: blob/main/doc/how_to/components/widget_from_values.md
2012 views

Construct Widgets from Data

This guide discusses how to automatically generate widget from data.


When working with data, be it in the form of lists, arrays or DataFrames it is common to want to filter that data. Manually computing the start and end values of a slider or the unique values of a dropdown can be an annoyance so widgets have a classmethod called from_values to help with this.

import pandas as pd import panel as pn pn.extension() # for notebook df = pd.read_csv("https://datasets.holoviz.org/penguins/v1/penguins.csv") species = pn.widgets.MultiSelect.from_values(df.species) species

As we can see the special constructor automatically inferred both the option and the name for the widget.

Similarly we can also use this to infer the values of a numeric column:

body_mass = pn.widgets.RangeSlider.from_values(df.body_mass_g) body_mass