I assume this to be the problem. What you are doing here is creating content dynamically. But instead of using pattern matching ID’s and callbacks, you have a fixed ID for the components.
Instead of creating the components on each call (on each change of selected_option
) I would just toggle the visibility of the components via the style
parameter.
Here an example:
Applied to your use case:
import dash
from dash import dcc, html, Input, Output
app = dash.Dash(__name__)
app.layout = html.Div(
[
html.Div(
[
dcc.Dropdown(
id='main_dropdown',
options=[1, 2],
multi=False,
value=1
)
]
),
html.Div(
id='additional_content',
children=[
dcc.Dropdown(
id='additional_dropdown_1',
options=[3, 4],
multi=False,
),
dcc.Dropdown(
id='additional_dropdown_2',
options=[5, 6],
multi=False,
)
]
),
html.Button(id='btn', children='dummy')
]
)
@app.callback(
Output('additional_content', 'style'),
Input('main_dropdown', 'value'),
)
def show_hide(selection):
if selection == 1:
return {}
return {'display': 'none'}
if __name__ == '__main__':
app.run(debug=True, port=8070)