How to connect your dashboard to data
This guide shows you how to connect your dashboard and your charts within the dashboard to data.
Vizro provides two ways to connect your charts to data. This section shows you how to use both.
Directly feed a Pandas DataFrame to your chart
You can directly feed a Pandas DataFrame to your chart. This is the simplest way to connect your charts to data.
Feed a Pandas DataFrame
px.data.iris() returns a Pandas DataFrame. We then pass this DataFrame to the
figure argument of the
If you are using JSON or YAML to define your dashboard, you can only use the data connector approach to connect your data.
Use a data connector
You can also connect your charts with a data connector. To use a data connector with Vizro, you need:
Define a data connector. A data connector is a function that returns a Pandas DataFrame. In this function, you can define how to load your data and then convert it to a Pandas DataFrame if necessary.
Register this function with the Vizro Data Manager. This allows you to use this data connector in your dashboard.
Use a Data Connector
When you use a data connector, you reference the data by string. In the example, we
px.scatter("iris", x="sepal_length", y="petal_width", color="species") to reference
the data. The string
"iris" is the dataset name registered in Data Manager. This is
how Vizro knows which data connector to use.
Data connector with arguments
You can also define a data connector with arguments. This is useful when you want to use the same data connector to load different data. For example, when you want to retrieve data from different tables in a database, you can define a data connector that accepts different SQL queries as arguments.
Use a Data Connector with Arguments
Kedro data catalog
If it is not a
kedro_datasets.pandas type, you need to build a
data connector to load the data from the data catalog and convert it to a Pandas
DataFrame, before you can register it with Vizro Data Manager.