You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use Dash pattern-matching callbacks extensively in my multi-page apps and make heavy use of the ALL wildcard. However, the callback architecture of my apps could be simplified further by introducing an option to allow partial matches, where a pattern with fewer keys matches components that have a superset of those keys.
This proposes an opt-in partial=True flag on Input, Output, and State.
Motivation
Currently, pattern-matching callbacks require the pattern and component to share exactly the same set of keys:
# Pattern: {"type": "btn", "index": ALL}# Only matches: {"type": "btn", "index": 1}, {"type": "btn", "index": 2}# Does NOT match: {"type": "btn", "index": 1, "page": "home"}
This forces developers to either:
Ensure all related components have identical key sets (rigid, often impractical)
Create separate callbacks for each key combination (verbose, duplicated logic)
Use callback_context workarounds to multiplex unrelated callbacks
I find with my apps I frequently have components that share a conceptual "type" but differ in their additional metadata keys — pages, sections, tabs, permissions, etc.
Proposed API
fromdashimportInput, Output, State, ALL, MATCH# Literal partial: matches all components with type="btn", regardless of extra keys@app.callback(Output("output", "children"),Input({"type": "btn"}, "n_clicks", partial=True),)defhandle_all_btns(n_clicks_list):
# Receives a list (implicitly multi-valued since multiple components match)returnf"Total: {sum(cor0forcinn_clicks_list)}"# With ALL wildcard: collects all components that have a "type" key@app.callback(Output("output", "children"),Input({"type": ALL}, "n_clicks", partial=True),)defhandle_any_type(n_clicks_list):
returnf"Collected {len(n_clicks_list)} components"# With MATCH: one-at-a-time on the shared key, ignoring extra keys@app.callback(Output({"type": "display", "index": MATCH}, "children", partial=True),Input({"type": "btn", "index": MATCH}, "n_clicks", partial=True),)defhandle_one(n_clicks):
returnf"Clicked {n_clicks} times"
Activity