Panel: A high-level app and dashboarding solution for the PyData ecosystem.

Philipp Rudiger
Jun 3 · 11 min read

Panel is a new open-source Python library that lets you create custom interactive web apps and dashboards by connecting user-defined widgets to plots, images, tables, or text. It is the culmination of our multi-year effort to connect data scientists with tools for deploying the output of their analysis and models with internal or external consumers of the analysis, without having to learn completely different technology stacks or getting into the weeds of web development. Panel can already be installed using both conda install -c pyviz panel (to get set up with Anaconda click here) and pip install panel. Like all other PyViz projects it is entirely open-source and BSD-3 licensed. To get started, visit the website here and find the Panel code on GitHub.

The main aim behind Panel was to make it as easy as possible to wrap the outputs of existing tools in the PyData ecosystem as a control panel, app, or dashboard, ensuring that users can seamlessly work with the analysis and visualization tools they are already familiar with. Secondly, Panel aims to make it trivial to go from prototyping an app to deploying it internally within an organization, or sharing it publicly with the entire internet.

Fast iteration

Most importantly, Panel apps can easily be built entirely within a Jupyter notebook, where a lot of modern data science happens. After an iterative process to slowly polish and improve the app or dashboard, it can then be deployed in a scalable way on a Bokeh-based server instance simply by annotating the objects to be deployed with a call to the .servable()method. The process of developing an app with Panel can therefore generally be broken down into a small number of steps:

  • Perform some analysis in a notebook, using whatever tools are convenient and effective for you
  • Wrap the output of your analysis as a Panel “pane”, allowing it to be used together with other Panel components
  • Connect the individual analysis outputs with widgets and other interactive components to form a full “panel”
  • Display these components in the notebook and iterate until you are happy with the result
  • Apply styling using CSS or built-in Bokeh styling options, if you wish
  • Test how the app or dashboard looks as a standalone web server by adding .show()
  • Make the app or dashboard deployable by annotating the components to be deployed with .servable()
  • Deploy the app locally or on a public server using panel serve nb.ipynb

This quick back-and-forth iteration between prototyping in a notebook and then deploying the final product is an incredibly convenient and powerful way to create a compelling and useful application, easily alternating between exploration and delivery of your insights to your audience. Thanks to the power of the underlying Bokeh layout engine and server, all the complex layout and styling options translate seamlessly between the different environments so that you can focus on your data and your audience.

Flexible APIs

A simple Panel app implemented in just a few lines of Python code.

As you can observe in the code, Panel provides a number of different abstraction layers to write this kind of app. To get a quick overview, let us look at the three most common APIs for building apps outlined in the Panel user guide.

Interact

Because Panel is compositional, we can index into the layout returned by the function, making it easy to write basic apps and lay them out precisely how you want.

Reactive

Thanks to the reactive programming model that underlies Panel, the plot will update whenever any of the declared dependencies of the function change.

Callbacks

Users can choose between these three different approaches to ensure they have just the right level of control needed for a particular use case, while being able to build dashboards of any complexity.

Compatibility with the Python ecosystem

In the previous example we rendered the plot using hvPlot (and Bokeh), but the same example works just as well with matplotlib, altair or Plotly. To demonstrate this let’s look at an example showing four plots of the Gapminder data implemented using each of these libraries, displayed in a single dashboard:

Gapminder data visualized using hvPlot (Bokeh), altair (Vega), Matplotlib and Plotly in one dashboard (Click here to try out the deployed app).

Dynamic dashboards

A classifier pipeline which allows 1) capturing images from a webcam and applying object detection to the images, 2) selecting and modifying the bounding boxes and 3) classifying the contents of the selected region using Google’s Vision API (To try it yourself here).

The ability to dynamically update and replace individual components — or the entire content of the app — opens up the flexibility to build everything from dynamic UIs to entire multi-stage, data processing pipelines.

Broad and expanding library of components

The reference gallery provides a visual index of all the components shipped with Panel.

Because Panel is built on the technology underlying Bokeh, it is straightforward to extend it with arbitrary custom models implemented in JavaScript. It is even simpler to implement a new Pane class that provides a visual representation for any Python object not currently handled by Panel. In this way, Panel can be easily extended to visualize objects of almost any type, and provide useful representations for objects anyone uses in their day-to-day work.

Layouts and styling

Lastly, Panel also provides a convenient way to embed multiple Panel components in a custom Jinja2 template providing full flexibility of the layout and the overall styling of the resulting HTML document.

Deployment

Over the coming weeks, we will also add detailed guides to explain the Python-server deployment procedure on different platforms, including AWS, Google Cloud, Heroku, and Anaconda Enterprise. In many cases, Panel objects can also be exported to static, standalone HTML/JavaScript files that no longer need a Python server, either by linking widgets to display properties using JS, or by sampling the output of the state space of a set of widgets, capturing the possible results in the file so that it can be distributed on websites or in emails without a running Python process.

Architecture

  • Bokeh provides the model-view-controller framework on which Panel is built, along with many of the core components such as the widgets and layout engine
  • Param provides a framework for reactive parameters which are used to define all Panel components.

The choice to build an API on top of Bokeh instead of simply extending it was driven by a number of core requirements. One of the most important was the ability to transition seamlessly between notebook and deployed server contexts, and doing so efficiently and in a scalable way. Another was the flexibility afforded by being able to dynamically generate a Bokeh representation for each view of a Panel object, encouraging reuse and composability of components. A third reason was to make it clear that Panel supports any viewable Python object, including plots from dozens of different libraries, not just Bokeh plots (Panel uses Bokeh internals and technology, but in no way assumes that you will use it with Bokeh plots).

Most importantly, however, we wanted to design an API that provides a high degree of both flexibility and simplicity. Many of the most common operations for displaying, saving, and serving a dashboard are exposed directly on Panel objects and uniformly across them, making it simpler to work with them. Additionally, updating and even dynamically adding/removing/replacing the individual components of a dashboard are as easy as manipulating a list or dictionary in Python. Of course, Panel should not be seen to be in competition with Bokeh; it simply provides higher-level abstractions on top of Bokeh. If needed, Bokeh components can easily be used from within Panel, and Panel components can easily be converted into Bokeh models which can be embedded in a larger Bokeh application.

Comparison to other dashboarding and widget libraries

Shiny

Jupyter/ipywidgets

Dash

Open source license & Community

Thanks for checking out Panel! We will be giving a talk and tutorial about it at SciPy 2019 in July and are actively working on building further materials, including more demos, tutorials, and examples in the coming weeks and months!

Acknowledgements

Further resources

Links

Talks

Philipp Rudiger

Written by

I am a Software Engineer at Anaconda, Inc. and author and maintainer of dashboarding & visualization tools such as Panel, hvPlot, HoloViews, GeoViews and Bokeh.