Panel Widgets#

This reference shows advanced widget functionality using Panel for fine-grained control over hvPlot interactivity. Panel provides extensive customization options beyond hvPlot’s built-in widget support.

Warning

The Panel APIs shown here may change in future versions.

Note

When viewing on a static website, the widgets will be inoperable. To explore this functionality fully, download the notebook and run it in a live python environment.

When to Use Advanced Panel Widgets#

The advanced Panel widget techniques shown in this reference are useful when you need more control than basic groupby widgets provide.

Use these techniques when you need to:

  • Control plot parameters beyond groupby dimensions (like x, y, kind, etc.)

  • Implement custom logic with pn.depends decorators

  • Create complex widget interactions and callbacks

  • Build sophisticated interactive dashboards

For simpler use cases:

  • If you just need to explore data by grouping dimensions, use the basic groupby parameter as shown in How to Explore with Widgets

  • The groupby approach automatically creates appropriate widgets without requiring Panel code

The examples below demonstrate advanced scenarios where direct Panel integration provides additional flexibility.

import panel as pn
import hvplot.pandas  # noqa

penguins = hvplot.sampledata.penguins("pandas").dropna()

Using Widgets as Plot Arguments#

Panel widgets can be used directly as arguments to hvPlot methods, allowing users to interactively select plot parameters like axes and plot types.

x = pn.widgets.Select(name='x', options=['bill_length_mm', 'bill_depth_mm'])
y = pn.widgets.Select(name='y', options=['flipper_length_mm', 'body_mass_g'])
kind = pn.widgets.Select(name='kind', value='scatter', options=['scatter', 'bivariate'])

plot = penguins.hvplot(x=x, y=y, kind=kind, colorbar=False, width=600)
pn.Row(pn.WidgetBox(x, y, kind), plot)

Using Functions with pn.depends#

For more complex interactions, you can create functions decorated with pn.depends that respond to widget changes.

x = pn.widgets.Select(name='x', options=['bill_length_mm', 'bill_depth_mm'])
y = pn.widgets.Select(name='y', options=['flipper_length_mm', 'body_mass_g'])
kind = pn.widgets.Select(name='kind', value='scatter', options=['scatter', 'bivariate'])
by_species = pn.widgets.Checkbox(name='By species')
color = pn.widgets.ColorPicker(value='#ff0000')

@pn.depends(by_species, color)
def by_species_fn(by_species, color):
    return 'species' if by_species else color

plot = penguins.hvplot(x=x, y=y, kind=kind, c=by_species_fn,
                       colorbar=False, width=400, legend='top_right')

pn.Row(pn.WidgetBox(x, y, kind, color, by_species), plot)

Widget Callbacks and Interactions#

You can also add callbacks to create more sophisticated widget interactions, such as enabling/disabling widgets based on other widget values.

def update(event):
    if kind.value == 'bivariate':
        color.disabled = True
        by_species.disabled = True
    else:
        color.disabled = False
        by_species.disabled = False

kind.param.watch(update, 'value');
This web page was generated from a Jupyter notebook and not all interactivity will work on this website.