Reactive Tables#
Download this notebook from GitHub (right-click to download).
import param
import panel as pn
from bokeh.sampledata.iris import flowers
from bokeh.sampledata.autompg import autompg_clean
from bokeh.sampledata.population import data
pn.extension(sizing_mode="stretch_width")
This example demonstrates Panel’s reactive programming paradigm using the Param library to express parameters, plus methods with computation depending on those parameters. This pattern can be used to update the displayed views whenever a parameter value changes, without re-running computation unnecessarily.
class ReactiveTables(param.Parameterized):
dataset = param.ObjectSelector(default='iris', objects=['iris', 'autompg', 'population'])
rows = param.Integer(default=10, bounds=(0, 19))
@param.depends('dataset')
def data(self):
if self.dataset == 'iris':
return flowers
elif self.dataset == 'autompg':
return autompg_clean
else:
return data
@param.depends('data')
def summary(self):
return self.data().describe()
@param.depends('data', 'rows')
def table(self):
return self.data().iloc[:self.rows]
def panel(self):
return pn.Row(
pn.Param(self, name="Settings", width=300, sizing_mode="fixed"),
pn.Column("## Description", self.summary, "## Table", self.table),
min_height=1000)
component = ReactiveTables().panel()
component
App#
Lets wrap it into nice template that can be served via panel serve reactive_tables.ipynb
pn.template.FastListTemplate(site="Panel", title="Reactive Data Tables",
main=[
"This example demonstrates [Panel's](https://panel.holoviz.org) reactive programming paradigm using the [Param](https://param.holoviz.org) library to express parameters, plus methods with computation depending on those parameters. \n\nThis pattern can be used to update the plots and tables whenever a parameter value changes, without re-running computations unnecessarily.",
component
]).servable();
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.
Download this notebook from GitHub (right-click to download).