Now I understand what you are after. Actually pattern matching callbacks don’t work like that.
The MATCH
does not refer to value
but rather to a matching component. Take this example:
from dash import Dash, html, Input, Output, MATCH, ctx
app = Dash(__name__)
app.layout = html.Div(
[
html.Div(
[
html.Button(f'button_{idx}', id={'type': 'btn', 'index': idx})
for idx in range(3)
]
),
html.Div(
[
html.Div(id={'type': 'out', 'index': idx})
for idx in range(3)
]
)
]
)
@app.callback(
Output({'type': 'out', 'index': MATCH}, 'children'),
Input({'type': 'btn', 'index': MATCH}, 'n_clicks'),
prevent_initial_call=True
)
def output(n_clicks):
triggered_index = ctx.triggered_id.index
return f'button wth index {triggered_index} has been clicked {n_clicks} times.'
if __name__ == '__main__':
app.run(debug=True)
mred pmcb