Linking Widgets#
Widget linking allows you to create interactive dashboards where selections in one widget dynamically affect other widgets. This enables user-driven interactions where selectable widgets can filter data displayed in tables, charts, and other display widgets based on user selections.
Selectable Widgets#
The following widgets support selection and can be used to drive interactivity:
- Search - Text-based search with dropdown selection
- Select - Dropdown menu for option selection
- Toggle - Switch-style option selection
- Table - Can function as selectable when rows are clickable
The selected
Property#
All selectable widgets expose a selected
property that provides access to the data of the currently selected item. This property can be used to reference the selected data in other widgets, creating dynamic relationships between components.
Examples#
Toggle + Table#
In this example, we create a toggle widget to select a region, and a table that updates based on the selected region:
import pandas as pd
from engineai.sdk.dashboard.data.connectors import Snowflake
from engineai.sdk.dashboard.widgets import table
from engineai.sdk.dashboard.widgets import toggle
# Create a toggle for region selection
region_toggle = toggle.Toggle(
id_column="id",
label_column="label",
data=pd.DataFrame({
"id": [1, 2, 3],
"label": ["North", "South", "West"]
}),
label="Select Region",
)
# Table that updates based on toggle selection
product_table = table.Table(
data=Snowflake(
slug="sales-data",
query=f"""
SELECT category, sales
FROM products
WHERE region_id = {region_toggle.selected.id}
""",
),
title=f"Product Sales in {region_toggle.selected.label}",
columns=["category", "sales"]
)
Table + Table#
In this example, we create a master table for customer selection, and a detail table that shows orders for the selected customer:
import pandas as pd
from engineai.sdk.dashboard.data.connectors import Snowflake
from engineai.sdk.dashboard.widgets import table
# Master table for customer selection
customer_table = table.Table(
data=Snowflake(
slug="customers",
query="""
SELECT customer_id, customer_name, region, total_orders
FROM customers
ORDER BY total_orders DESC
""",
),
title="Select Customer",
columns=["customer_id", "customer_name", "region", "total_orders"],
)
# Detail table showing orders for selected customer
orders_table = table.Table(
data=Snowflake(
slug="orders",
query=f"""
SELECT order_id, order_date, product_name, quantity, amount
FROM orders
WHERE customer_id = {customer_table.selected.customer_id}
ORDER BY order_date DESC
""",
),
title=f"Orders for {customer_table.selected.customer_name}",
columns=["order_id", "order_date", "product_name", "quantity", "amount"]
)