Path: blob/main/doc/tutorials/intermediate/structure_data_store.md
3220 views
Structure with a DataStore
Welcome to the tutorial on structuring our Panel app with a DataStore! Here, we'll delve into the powerful DataStore design pattern, which forms the backbone of many successful applications.
Understanding the DataStore Design Pattern
The DataStore design pattern has emerged as a reliable solution across diverse application scenarios. At its core:
Data Transformation: The
DataStorecomponent ingests rawdataalong withfilters, and then orchestrates transformations based on these inputs.Consumption by Views: Transformed data is then consumed by one or more
Viewcomponents, enabling flexible visualization and interaction.Reusable Components: These components are designed to be reusable, facilitating seamless integration in both notebooks and standalone applications.
Build the App
The Data Store
Let's start by creating the core DataStore component. Copy the following code into a new file named data_store.py.
:::{note} The DataStore class serves as the engine for transforming data. It performs various transformations based on provided filters.
Initialize with
data.Update calculations when
filterschange. :::
Continuing with Views
After defining the DataStore, we'll create View components that leverage the transformed data. This enables diverse ways of visualizing and interacting with the data. Copy the code into a new file named views.py.
:::{note} By establishing a base View class linked to the DataStore, we can create various concrete View classes tailored to different visualization requirements. :::
Assembling the App
With the DataStore and View components in place, we'll now assemble the complete app. Copy the code below into a new file named app.py.
Once saved, run panel serve app.py --dev in your terminal to launch the app.
The app will look something like

Reuse in a Notebook
The compositional approach of constructing application components enables their seamless integration into various contexts, including notebooks. Copy the following cells into a notebook, ensuring to uncomment the imports, and execute them.
Recap
In this tutorial, we've explored:
The versatility of the
DataStoredesign pattern, which adapts to diverse use cases.The seamless integration of
DataStoreandViewcomponents, enabling flexible data exploration and visualization.The reusability of these components across notebooks and standalone applications.
Ready to apply these principles in your own projects? Let's embark on your Panel journey! 🚀