Display Content with Panes
In this tutorial, we will learn to display objects with Panes:
Panes are available in the
pn.pane
namespace.Panes take an
object
argument as well as other arguments.Discover all Panes and their reference guides in the Panes Section of the Component Gallery.
:::{note} A Pane is a component that can display an object. It takes an object
as an argument. :::
:::{note} You might notice a lot of repetition from the previous section regarding pn.panel
. Don't worry, it's intentional! We're doing this to empower you with the ability to compare and contrast. While pn.panel
is incredibly user-friendly and versatile, specific Panes allow you to display output with precision and efficiency. This enables you to construct more intricate and high-performing applications. :::
:::{note} When we ask you to run the code in the sections below, you may either execute the code directly in the Panel docs via the green run button, in a cell in a notebook, or in a file app.py
that is served with panel serve app.py --dev
. :::
Display Strings
The Str
pane can display any text.
Run the code:
:::{note} We add .servable()
to the component to add it to the app served by panel serve app.py --dev
. Adding .servable()
is not needed to display the component in a notebook. :::
:::{note} To learn in detail how a pane like Str
works, refer to its reference guide. :::
Click this link to the Str
reference guide and spend a few minutes to familiarize yourself with its organization and content.
Display Markdown
The Markdown
pane can format and display markdown strings.
Run the code:
:::{tip} It's key for success with Panel to be able to navigate the Component Gallery and use the reference guides. :::
Click this link to the Panes Section of the Component Gallery. Identify the Markdown Reference Guide and open it. You don't have to spend time studying the details right now.
Display Alerts
The Alert
pane can format and display markdown strings inside a nicely styled Alert pane.
Run the code:
Display Plots
Pick a plotting library below.
:::::{tab-set}
::::{tab-item} Altair :sync: altair
Run the code below.
:::{note} Vega is the name of the JavaScript plotting library used by Altair.
We must add "vega"
as an argument to pn.extension
in the example to load the Vega Javascript dependencies in the browser.
If we forget to add "vega"
to pn.extension
, then the Altair figure might not display. :::
::::
::::{tab-item} ECharts :sync: echarts
Run the code below.
:::{note} We must add "echarts"
as an argument to pn.extension
in the example to load the ECharts Javascript dependencies in the browser.
If we forget to add "echarts"
to pn.extension
, then the ECharts figure might not display. :::
::::
::::{tab-item} hvPlot :sync: hvplot
Run the code below.
:::{note} hvPlot is the easy to use plotting sister of Panel. It works similarly to the familiar Pandas .plot
api. hvPlot is built on top of the data visualization library HoloViews. hvPlot, HoloViews, and Panel are all part of the HoloViz family. :::
::::
::::{tab-item} Matplotlib :sync: matplotlib
Run the code below.
:::{note} In the example, we provide the arguments dpi
, format
and tight
to the Matplotlib pane.
The Matplotlib
pane can display figures from any framework that produces Matplotlib Figure
objects like Seaborn, Plotnine and Pandas .plot
.
We can find more details in the Matplotlib Reference Guide. :::
::::
::::{tab-item} Plotly :sync: plotly
Run the code below.
:::{note} We must add "plotly"
as an argument to pn.extension
in the example to load the Plotly JavaScript dependencies in the browser.
If we forget to add "plotly"
to pn.extension
, then the Plotly figure might not display. :::
::::
::::{tab-item} Vizzu :sync: vizzu
Run the code below.
:::{note} We must add "vizzu"
as an argument to pn.extension
in the example to load the Vizzu JavaScript dependencies in the browser.
If we forget to add "vizzu"
to pn.extension
, then the Vizzu figure might not display. :::
::::
:::::
Display a DataFrame
Run the code:
:::{note} If we want to display larger dataframes, customize the way the dataframes are displayed, or make them more interactive, we can find specialized components in the Component Gallery supporting these use cases. For example, the Tabulator widget and Perspective pane. :::
Display any Python object
Provides Panes to display (almost) any Python object.
Run the code below
Recap
In this guide, we have learned to display Python objects with Panes:
Panes are available in the
pn.pane
namespacePanes take an
object
argument as well as other argumentsDisplay plot figures like Altair, ECharts, hvPlot, Matplotlib, Plotly and Vizzu with the
Vega
,ECharts
,HoloViews
,Matplotlib
,Plotly
andVizzu
panes, respectively.Display DataFrames with the
DataFrame
andPerspective
panes.Add JavaScript dependencies via
pn.extension
. For examplepn.extension("vega")
orpn.extension("plotly")
Discover all Panes and their reference guides in the Panes Section of the Component Gallery.