Pattern matching callbacks: why can't an INPUT with MATCH feed an OUTPUT that is fixed (no MATCH or ALL)

It seems that the typical use case for pattern-matching callbacks is to associate a dynamic input and output together via MATCH (or ALL). One could create multiple instances of this INPUT/OUTPUT combination. However, I have a use case where I have many INPUT buttons that all feed one text div output. I would have a very simple callback definition if I could do this:

    Output("output_div_id", "children"),
    Input({'type':"generic_btn", "index":MATCH}, 'n_clicks') # this would match any of several buttons.

It seems this is not allowed as the Output needs to have MATCH in it as well. Why is this? Am I missing something? Without this, my Input list needs to contain all the button inputs which is not very scalable.

1 Like

Hi @vonf,

Interesting questions! I don’t have all the knowledge to answer then, so I am doing it mostly to activate this thread and see if someone can explain in better details.

It seems to me that the reason is purely because it wasn’t implemented with this particular use case in mind, but again, I don’t know the details behind dash-renderer and this could break something further along the line. In any case, the error is raised in the javascript side and catches this case you presented exactly.

(Or perhaps this is just not needed, see below)

Without this, my Input list needs to contain all the button inputs which is not very scalable.

You can use roughly the same callback signature replacing MATCH to ALL and using dash.callback_context.triggered inside the callback to identify which element of the input list is the updated value for the component that triggered the callback execution. Yes, it is a bit more convoluted, but not “unscalable” (if you were thinking in terms of typing all the inputs explicitly).

You can find more details about the context here, under " Determining which Input has fired with dash.callback_context".

1 Like