Building a Panel Pipeline

Updated: Oct 19

Over a number of recent posts, we have given some examples of how to build dashboards using Panel and how to integrate widgets from Panel and ipywidgets into the same Panel app. These have all been one-stage examples, but you can actually use Panel to build a pipeline of stages with information carried over from one stage to the next. You can think of these stages as different pages on a website.


In this post, we present an example of a simple pipeline using Panel to illustrate how easy it is to put in place.


Instantiating the Pipeline


We start by importing Panel, then instantiating a Panel Pipeline object called pipeline. In this instance, we include the inherit_params parameter, setting it to False. If inherit_params is True, then parameters declared on consecutive stages are inherited. It will not matter in our simple example, but enabling inherited parameters across pipeline stages may be useful in some application contexts.

import panel as pn

pn.extension()

pipeline = pn.pipeline.Pipeline(inherit_params=False)

Building Stages


Next, we can add stages to the pipeline. To do so, we need to build the additional stages explicitly.


To construct a Panel pipeline, we need to create parameterized classes (i.e., classes that inherit from the param.Parameterized class from the Param library). Param enables declarative programming in Python; that is, we can simply state facts about our parameters and then use them throughout our code. Within Panel apps, the panel.depends decorator function links parameter values to callback functions to update the state of the Panel app. In Panel pipelines, the param.output decorator function links computed values between successive stages. The parameters received at a given stage in a pipeline must be declared consistently to consume output from the previous stage.


In addition, we need a panel method in each stage of the pipeline to determine the layout of panes & widgets in the Panel app.


The class Stage1 defined below displays a text input widget and a continue button. The text entered into Stage1 is passed on to the next stage (Stage2). To do this, we define a string parameter text and an output method with the param.output('text') decorator. This indicates that text is the output of this stage.


Notice also that we