Noticed that the Dash (currently using v2.14) doesn’t support mixing patterning matching and specific ids. Is that a known behavior?
In my setup I have 6 different pages - each has it’s own timer.
- 3 kinds of analytics pages - each has it’s own set of table that i display
- 3 kinds of charts - various kinds of plots
- Each of these pages has their own timer. Each timer is set between an update of 1 second to 120 seconds, with a goal of refreshing these pages in that frequency
A single page, which I here call as strategy daily_analytics, has a callback that is meant to update 8 tables on that page. Instead of creating a callback for each table I created a pattern matching callback.
The id of the components on this page is a dictionary:
property_id = dict(
strategy=<page_strategy>, # kind of high level sub-category of the app
index=<element_name>, # i.e. kind of table as I have a table per region, product etc.
type=<page_type>, # i.e. summary or chart
element=<element_type> # i.e. div/table
)
E.g.
Callback with specific ids:
@callback(
Output({'strategy': 'daily_analytics', 'index': 'region', 'type': 'summary', 'element': 'div'}, 'style', allow_duplicate=True),
Output({'strategy': 'daily_analytics', 'index': 'region', 'type': 'summary', 'element': 'table_div'}, 'children', allow_duplicate=True),
Input({'strategy': 'daily_analytics', 'index': 'analytics_timer', 'type': 'summary', 'element': 'timer'}, 'n_intervals'),
Input('url', 'pathname'),
Input({'strategy': 'daily_analytics', 'index': 'client_mtime', 'type': 'summary', 'element': 'mtime'}, 'children',),
Input({'strategy': 'daily_analytics', 'index': 'region', 'type': 'summary', 'element': 'table'}, 'sort_by'),
State({'strategy': 'daily_analytics', 'index': 'region', 'type': 'summary', 'element': 'table'}, 'id'),
prevent_initial_call=True,
)
This one works perfectly. There is no ambiguity.
As I replace the specific index
values (i.e. region
here) with MATCH
it stops working.
E.g.
@callback(
Output({'strategy': 'daily_analytics', 'index': MATCH, 'type': 'summary', 'element': 'div'}, 'style', allow_duplicate=True),
Output({'strategy': 'daily_analytics', 'index': MATCH, 'type': 'summary', 'element': 'table_div'}, 'children', allow_duplicate=True),
Input({'strategy': 'daily_analytics', 'index': 'analytics_timer', 'type': 'summary', 'element': 'timer'}, 'n_intervals'),
Input('url', 'pathname'),
Input({'strategy': 'daily_analytics', 'index': 'client_mtime', 'type': 'summary', 'element': 'mtime'}, 'children',),
Input({'strategy': 'daily_analytics', 'index': MATCH, 'type': 'summary', 'element': 'table'}, 'sort_by'),
State({'strategy': 'daily_analytics', 'index': MATCH, 'type': 'summary', 'element': 'table'}, 'id'),
prevent_initial_call=True,
)
The assumption here is that MATCH would take care of updating the matching tables.
It ONLY works for the “sort_by” input. i.e. if any of the column sort (from the 8 tables) is triggered that table is updated.
But the timer input is NOT triggering any updates. Looked through the dash.callback_context.triggered
and it doesn’t have the timer.
Whenever the sort is triggered the n_intervals
argument is an updated value. Testing by logging all the inputs.
So the question is how to “trigger” the callback based on timer in such case?