Creating single dropdown callback with variable input names

so basically, I want my callback to be dynamic(e.g. reusable for {x}_dropdown, where {x} is generated from a list.

I render the correct amount of divs, each with dropdowns.

return html.Div(
            [
                html.Div(
                    [
                        html.H3("{}".format(_)),
                        dt.DataTable(
                            data=dff.loc[dff["Keyword"] == str(_)].to_dict('records'),
                            columns=[{"name": str(i), "id": str(i), "presentation": 'dropdown'} for i in
                                     dff.columns],
                            hidden_columns=["NER_TAGS", "Keyword"],
                            css=[{"selector" : ".show-hide", "rule" : "display: none"}],
                            style_cell={
                                'overflow': 'hidden',
                                'textOverflow': 'ellipsis',
                                'textAlign': 'left',
                                'maxWidth': 0
                            },
                            tooltip_data=[
                                {
                                    column: {'value': str(value), 'type': 'markdown'}
                                    for column, value in row.items()
                                } for row in dff.to_dict('rows')
                            ],
                            tooltip_duration=None

                        ),
                        dcc.Dropdown(
                            id='{}-dropdown'.format(_),
                            options=[
                                {'label': i, 'value': i} for i in df["NER_TAGS"].unique()
                            ]
                        )
                    ]
                ) for _ in kw_names
            ]

            + [
                html.Div(id='dd-output-container'),

                html.Br(),
                html.Br(),

                html.Div(
                    [
                        dcc.Link(
                            html.Button('Back', n_clicks=0),
                            href='/index'
                        ),

                        dcc.Link(
                            html.Button('Train NER Model', id='train-ner-btn')
                        ),
                    ], className="row"
                ),

                html.Br(),
                html.Br(),

                html.Div(
                    [
                        html.Div
                            (
                            id='train-prog'
                        )
                    ], className="row"
                )
            ]
        )

I have my callback below which I modified from the dash dcc.input first example

@app.callback(
    Output('dd-output-container', 'children'),
    [Input('{}-dropdown'.format(_), 'value') for _ in kw_names],)
def update_output(dd_value):
    print(dd_value)

I am currently unable to trigger the callback if I use the for loop with {}_dropdown as the Input ID. The callback triggers if I hardcode the id in, which is not what I want as my program generates a user-specified amount each time.

Any help/suggestions/solutions are welcomed. Thanks!

I’d recommend checking out pattern matching callbacks for dynamic callbacks: dash.plotly.com/pattern-matching-callbacks

oh my gosh, thanks so much, this works. can’t believe I spent days trying to figure this out.