Panel: Data Exploration & Web App Framework
Panel is an open-source Python library that allows you to easily create interactive web-based dashboards and applications directly from Python code. It integrates seamlessly with the PyData ecosystem, offering powerful, interactive data tables, visualizations, and more. It supports rapid development of exploratory applications and building complex, multi-page apps with rich interactivity. [2, 3]
Warnings
- gotcha Always call `pn.extension()` in Jupyter/IPython notebooks. Forgetting this can lead to unexpected display issues or lack of interactivity, as it sets up crucial JavaScript dependencies and communication channels. [19]
- gotcha Avoid mutable default arguments in functions or methods used with Panel's reactivity, especially if they are modified. Python evaluates default arguments once when the function is defined, leading to shared state across calls if the default is mutable (e.g., a list or dictionary). [20, 21]
- gotcha Be cautious when using `watch=True` with `param.depends` decorators on methods that are already displayed in a Panel layout. Panel automatically monitors dependencies for displayed components, and explicitly setting `watch=True` can cause the method to be invoked twice. [8]
- gotcha Frequent updates to Panel and its underlying dependencies (like Bokeh, Plotly, Vega, Tabulator) mean that specific versions of these libraries might be required for optimal compatibility. For example, recent releases often include fixes for compatibility with newer Bokeh versions. [14, 15]
- gotcha Using `pn.panel()` is convenient for displaying various Python objects, but for performance-critical applications, it's often more efficient to directly use specific `pn.pane` types (e.g., `pn.pane.Markdown`, `pn.pane.Plotly`) if you know the object type. `pn.panel()` uses a heuristic that might not always be the most performant. [10]
Install
-
pip install panel
Imports
- panel
import panel as pn
- extension
pn.extension()
Quickstart
import panel as pn
pn.extension()
# Create a simple Panel component
hello_world_pane = pn.pane.Markdown("## Hello, Panel!")
# Display the component in a server app
# In a Jupyter/IPython notebook, this will display the app inline.
# To serve as a standalone app, save as `app.py` and run `panel serve app.py --dev`
hello_world_pane.servable()