Interactive Panel App with bind
#
An interactive app that filters penguins by species and body mass threshold using Panel widgets and setting up interactivity with pn.bind
. The filtered data is visualized as a scatter plot.
import panel as pn
import hvplot.pandas # noqa
df = hvplot.sampledata.penguins("pandas").dropna()
species_widget = pn.widgets.Select(
name='Species',
options=list(df['species'].unique()),
width=200,
)
mass_widget = pn.widgets.IntSlider(
name='Min Body Mass (g)',
start=int(df['body_mass_g'].min()),
end=int(df['body_mass_g'].max()),
step=100,
value=4000,
width=200,
)
def plot_penguins(species, min_mass):
subset = df[(df['species'] == species) & (df['body_mass_g'] >= min_mass)]
return subset.hvplot.scatter(
x='bill_length_mm',
y='bill_depth_mm',
color='body_mass_g',
cmap='viridis_r',
size=24,
title=f'{species} Penguins (body mass ≥ {min_mass})',
xlabel='Bill Length (mm)',
ylabel='Bill Depth (mm)',
)
plot = pn.bind(plot_penguins, species=species_widget, min_mass=mass_widget)
pn.Column(pn.Row(species_widget, mass_widget), plot)
This web page was generated from a Jupyter notebook and not all
interactivity will work on this website.