Reading from a dropdown generated dynamically

Hello,

I am trying to create an interactive dashboard, that shows different graphics depending on the user selection.

The idea is to have a first dropdown, and depending on the selection that the user show another dropdown. Based on the selection done on the second dropdown, I want to display one graph or another.

  • First dropdown: id = “selection_1”
  • Second dropdown (dynamically generated): id = “output_1”
  • Graph output: id = “output_1_1”

My problem is that I do not know how to pass the user selection of the second dropdown to the second callback, and my code is not working (i did not include the graph code to make it simpler to read)

This is my code:

app.layout = html.Div(children=[
html.Div([
dcc.Dropdown(
id=‘selection_1’,
options =[
{‘label’: ‘Display airports network in map’, ‘value’: 0},
{‘label’: ‘Others’, ‘value’: ‘1’},
],
#value = ‘1’ ## default value
),
],
),

    html.Div(id='output_1'),
    
    html.Div(id='output_1_1'),

])

@app.callback (
Output(‘output_1’,‘children’),
[Input(‘selection_1’,‘value’)]
)

def first_selection (selected):
if selected == 0:
Div = html.Div([

            html.Div([               
                'Select what network you want to display:'                   
                ],
                style = {'width':'20%', 'marginLeft':'10px','display':'inline-block'}
                ),
            
            html.Div([
                dcc.Dropdown(
                 id='dropdown_2',
                 options=[{'label': 'Complete network', 'value': 0},
                          {'label': 'Select component to display', 'value': 1},
                 placeholder='Select the dataset...',
                 )       
                ],
                style = {'width':'20%','marginTop':'10px', 'display':'inline-block'}
                )
            ],
        ),
    return Div
else:
    return None

@app.callback (
Output(‘output_1_1’,‘children’),
[Input(‘selection_1’,‘value’),
Input(‘output_1’,‘value’)]
)

def plot_whole_network (selection_1,selection_2):
if (selection_1 == 0) and (selection_2 == 0):
‘’ Write here to return one grahp
return Graph
else:
‘’ Write here to return another graph
return Graph

Thank you very much,