Getting Started

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.

Installation

CondaPyViz CondaDefaults PyPI License

Panel works with Python 2.7 and Python 3 on Linux, Windows, or Mac. The recommended way to install Panel is using the conda command provided by Anaconda or Miniconda:

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

Using Panel

Note: This guide is written for an interactive environment such as Jupyter notebooks. The interactive widgets will not work in a static version of this documentation.


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:

In [1]:
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()
Out[1]:
Temperature Humidity Light CO2 HumidityRatio Occupancy
date
2015-02-10 09:29:00 21.05 36.0975 433.0 787.250000 0.005579 1
2015-02-10 09:29:59 21.05 35.9950 433.0 789.500000 0.005563 1
2015-02-10 09:30:59 21.10 36.0950 433.0 798.500000 0.005596 1
2015-02-10 09:32:00 21.10 36.2600 433.0 820.333333 0.005621 1
2015-02-10 09:33:00 21.10 36.2000 447.0 821.000000 0.005612 1

And we've written some code that smooths a time series and plots it using Matplotlib with outliers highlighted:

In [2]:
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:

In [3]:
find_outliers(variable='Temperature', window=20, sigma=10)
Out[3]:

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.

Interactive Panels

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:

In [4]:
import panel as pn
pn.extension()

pn.interact(find_outliers)