Dynamic Text#
When a string parameter supports the type TemplatedString, it can be used to create dynamic text that updates automatically based on user interactions or data changes. This powerful feature enables you to build responsive dashboards where text content adapts in real-time to user selections and widget states.
Example#
The following example demonstrates how dynamic text creates a responsive dashboard where the table title updates based on toggle selection.
The table's title
parameter uses a templated string that references the region_toggle
selected label, so when a user selects "North" in the toggle, the title becomes "Product Sales in North", and the title automatically updates whenever the toggle selection changes.
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}", # Dynamic text
columns=["category", "sales"]
)