# Creating single dropdown callback with variable input names

**URL:** <https://community.plotly.com/t/creating-single-dropdown-callback-with-variable-input-names/44899>\
**Category:** Dash Python\
**Created:** [September 15, 2020, 3:58am UTC](https://community.plotly.com/t/creating-single-dropdown-callback-with-variable-input-names/44899 "2020-09-15T03:58:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![danltw](https://avatars.discourse-cdn.com/v4/letter/d/e495f1/32.png) [@danltw](https://community.plotly.com/u/danltw)\
**Post date:** [September 15, 2020, 3:58am UTC](https://community.plotly.com/t/creating-single-dropdown-callback-with-variable-input-names/44899/1 "2020-09-15T03:58:23Z")

</div>

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.

```auto
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](https://dash.plotly.com/dash-core-components/input)

```auto
@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!

---

<div class="post-metadata">

**Author:** ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)\
**Post date:** [September 15, 2020, 5:05am UTC](https://community.plotly.com/t/creating-single-dropdown-callback-with-variable-input-names/44899/2 "2020-09-15T05:05:28Z")

</div>

I’d recommend checking out pattern matching callbacks for dynamic callbacks: [dash.plotly.com/pattern-matching-callbacks](http://dash.plotly.com/pattern-matching-callbacks)

---

<div class="post-metadata">

**Author:** ![danltw](https://avatars.discourse-cdn.com/v4/letter/d/e495f1/32.png) [@danltw](https://community.plotly.com/u/danltw)\
**Post date:** [September 15, 2020, 6:55am UTC](https://community.plotly.com/t/creating-single-dropdown-callback-with-variable-input-names/44899/4 "2020-09-15T06:55:03Z")

</div>

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