Welcome to Panel!
This section will get you set up with Panel and provide a basic overview of the features and strengths of Panel. The announcement blog is another great resource to learn about the features of Panel and get an idea of what it can do.
conda install -c pyviz panel
or using PyPI:
pip install panel
Support for classic Jupyter Notebook is included with Panel. If you want to work with JupyterLab, you will also need to install the optional PyViz JupyterLab extension:
conda install -c conda-forge jupyterlab jupyter labextension install @pyviz/jupyterlab_pyviz
Panel lets you add interactive controls for just about anything you can display in Python. Panel can help you build simple interactive apps, complex multi-page dashboards, or anything in between. As a simple example, let's say we have loaded the UCI ML dataset measuring the environment in a meeting room:
import pandas as pd; import numpy as np; import matplotlib.pyplot as plt data = pd.read_csv('../assets/occupancy.csv') data['date'] = data.date.astype('datetime64[ns]') data = data.set_index('date') data.tail()
And we've written some code that smooths a time series and plots it using Matplotlib with outliers highlighted:
from matplotlib.figure import Figure from matplotlib.backends.backend_agg import FigureCanvas %matplotlib inline def mpl_plot(avg, highlight): fig = Figure() FigureCanvas(fig) # not needed in mpl >= 3.1 ax = fig.add_subplot() avg.plot(ax=ax) if len(highlight): highlight.plot(style='o', ax=ax) return fig def find_outliers(variable='Temperature', window=30, sigma=10, view_fn=mpl_plot): avg = data[variable].rolling(window=window).mean() residual = data[variable] - avg std = residual.rolling(window=window).std() outliers = (np.abs(residual) > std * sigma) return view_fn(avg, avg[outliers])
We can call the function with parameters and get a plot:
find_outliers(variable='Temperature', window=20, sigma=10)
It works! But exploring all these parameters by typing Python is slow and tedious. Plus we want our boss, or the boss's boss, to be able to try it out.
If we wanted to try out lots of combinations of these values to understand how the window and sigma affect the plot, we could reevaluate the above cell lots of times, but that would be a slow and painful process, and is only really appropriate for users who are comfortable with editing Python code.
Instead of editing code, it's much quicker and more straightforward to use sliders to adjust the values interactively. You can easily make a Panel app to explore a function's parameters using
pn.interact, which is similar to the ipywidgets interact function:
import panel as pn pn.extension() pn.interact(find_outliers)