Layout Content
Welcome to our guide on layouting Python objects, including Panel components! Let's dive into arranging your content in a visually appealing and organized manner.
Explore Layouts
In this guide, we'll explore the following aspects of layouts:
Layouts: Accessible in the
pn
namespace.Layout Techniques: Utilize
pn.Column
andpn.Row
to structure your content.Reference Guides: Explore detailed documentation for each layout in the Layouts Section of the Component Gallery.
:::{note} As you follow along with the code examples below, feel free to execute them directly in the Panel documentation, a notebook cell, or within a file named app.py
served with panel serve app.py --dev
. :::
Layout in a Column
Let's start by arranging objects vertically using the Column layout.
Run the code below:
:::{note} The Column
layout organizes the elements "# Wind Speed"
, data
, and button
vertically.
We add .servable()
to display the Column
component in a server app. It's not necessary for displaying it in a notebook. :::
Click this link to access the Column
reference guide and familiarize yourself with its functionality.
Layout in a Row
Next, let's arrange objects horizontally using the Row
layout.
Run the code below:
Displays using pn.panel
Layouts automatically display objects using pn.panel
.
Run the code below:
The print
statement will output something like:
Under the hood, the Column
layout uses pn.panel
to determine how to best display Python objects.
:::{tip} You can customize how objects are displayed using various arguments of pn.panel
, specific Panes, or specific Widgets. :::
Run the code below to see custom display:
Works like a list
Column
, Row
, and many other layouts behave like lists.
Run the code below:
:::{note} We utilize the list-like properties of the Column
layout to rearrange its elements using list-indexing as in component[0], component[2], component[1]
.
The Column
layout implements all the methods you would expect from a list-like object, including .append
and .remove
. :::
Combine Layouts
To create more complex layouts, we can combine and nest layouts.
Let's run the code below:
Explore the Layouts
Panel provides a vast collection of layouts to suit your needs.
Click this link to explore available layouts and their detailed reference guides.
Recap
In this guide, we have learned:
Layouts: Available in the
pn
namespace.Layout Techniques: Utilize
pn.Column
andpn.Row
to structure your content.Automatic Display: Layouts use
pn.panel
to determine the optimal display for Python objects.List-like Behavior: Layouts like
Column
andRow
behave like lists, allowing for flexible manipulation.Complex Layouts: Combine and nest layouts for more intricate arrangements.
Now, you're equipped to create dynamic and visually appealing layouts for your Panel apps!