Reactive plots

Download this notebook from GitHub (right-click to download).

The iris dataset is a standard example used to illustrate machine-learning and visualization techniques. Here, we show how to use Panel to create a dashboard for visualizing the dataset. The Panel dashboard uses hvPlot to create plots and Param objects to create options for selecting the X and Y axis for the plot. First, let's import the packages we are using:

In [ ]:
import hvplot.pandas
import param
import panel as pn

from bokeh.sampledata.iris import flowers


The flowers dataset we imported from Bokeh has five columns: sepal_length, sepal_width, petal_length, petal width, and species.

In [ ]:

We will start by using the dataframe with these five features and then create a Selector object to develop menu options for different input features. Later we will define the core plotting function in a plot method and define the layout in the panel method of the IrisDashboard class.

The plot method watches the X_variable and Y_variable using the param.depends decorator, setting the watch option of this decorator to True. The plot method plots the features selected for X_variable and Y_variable and colors them using the species column.

In [ ]:
inputs = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width']
class IrisDashboard(param.Parameterized):
    X_variable = param.Selector(inputs, default=inputs[0])
    Y_variable = param.Selector(inputs, default=inputs[1])
    @param.depends('X_variable', 'Y_variable')
    def plot(self):
        return flowers.hvplot.scatter(x=self.X_variable, y=self.Y_variable, by='species')
    def panel(self):
        return pn.Row(self.param, self.plot)

dashboard = IrisDashboard(name='Iris_Dashboard')

And now you can explore how each of the input columns relate to each other, either here in the notebook or when served as a separate dashboard using panel serve --show Iris_dataset.ipynb:

In [ ]:

Download this notebook from GitHub (right-click to download).