Hi, I am trying to do the following.
I have two list, I want “list_one” to show first, and when “list_one” is called, I want “list_two” to show. The problem I am having is that I can not get the second list to show.
Eventually, I want to make it such that, depending on your choice in “list_one”, different list options will appear
dash 1.21.0
dash-core-components 1.14.1
dash-html-components 1.1.4
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State, MATCH, ALL
list_one = ['NYC', 'MTL', 'LA', 'TOKYO']
list_two = ['food', 'sight-seeing', 'hiking', 'dancing']
app = dash.Dash(__name__, suppress_callback_exceptions=True)
app.layout = html.Div([
html.Button("Add Filter", id="dynamic-add-filter", n_clicks=0),
html.Div(id='dynamic-dropdown-container', children=[]),
html.Div(id ='dynamic-dropdown-container-filter',children=[])
])
@app.callback(
Output('dynamic-dropdown-container', 'children'),
Input('dynamic-add-filter', 'n_clicks'),
State('dynamic-dropdown-container', 'children'))
def display_dropdowns(n_clicks, children):
new_element = html.Div([
dcc.Dropdown(
id={
'type': 'dynamic-dropdown',
'index': n_clicks
},
options=[{'label': i, 'value': i} for i in list_one] # my traces
),
])
children.append(new_element)
return children
@app.callback(
Output({'type': 'dynamic-dropdown-filter', 'index': MATCH}, 'children'),
Input({'type': 'dynamic-dropdown', 'index': MATCH}, 'value'),
State({'type': 'dynamic-dropdown', 'index': MATCH}, 'id'),
)
def display_output(value, id):
children = []
new_element = html.Div([
dcc.Dropdown(
id='id['index]',
options=[{'label': i, 'value': i} for i in list_2] # my traces
)])
children.append(new_element)
return children
if __name__ == '__main__':
app.run_server(debug=True)```
Thank you in advance