Page Dependencies#
Page dependencies enable you to create dynamic dashboards that respond to URL parameters and share data across widgets. By using routes with query parameters, you can build pages that dynamically filter and display data based on user input or URL state.
The route data is shared across the entire dashboard, meaning any widget on the page can access and use this data. This allows you to create cohesive dashboards where multiple widgets display different aspects of the same filtered dataset.
Example#
This example demonstrates how to create a stock lookup dashboard that uses a URL query parameter to filter stock data, which is available across the dashboard, and display it in a table widget.
from engineai.sdk.dashboard.dashboard import Dashboard
from engineai.sdk.dashboard.data.connectors import Snowflake
from engineai.sdk.dashboard.links import UrlQueryDependency
from engineai.sdk.dashboard.widgets import table
# Get query parameter from URL
symbol_param = UrlQueryDependency(field="symbol")
# Define route with query parameter
route = dashboard.Route(
data=Snowflake(
query=f"SELECT symbol, name, price, volume FROM stocks WHERE symbol = '{symbol_param}'",
slug="stock-lookup",
),
query_parameter="symbol",
)
# Create widgets that use route data
stock_table = table.Table(
title=f"Stock Details: {route.selected.symbol}",
data=route.selected,
columns=["symbol", "name", "price", "volume"],
)
# Create page with route dependency
page = dashboard.Page(
content=[stock_table],
title=f"Stock Dashboard - {route.selected.symbol}",
route=route,
)
# Attach the page to a dashboard
Dashboard(
workspace_slug="my-workspace",
app_slug="my-app",
slug="my-dashboard",
content=page,
)