Imagine three dropdowns with the same option list.
What I want is if the user selects a value from the first dropdown it should remove that particular value from the other 2 dropdowns. So basically the user can’t select the value that was already selected from the first dropdown.
I tried different workarounds but couldn’t do it.
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
app = dash.Dash(__name__)
options = ['Anime', 'Manga', 'Video Games', 'Music']
def get_dropdown(id):
dropdown = dcc.Dropdown(
id=id,
options=[{'label': i, 'value': i} for i in options],
)
return dropdown
app.layout = html.Div([
html.Div(get_dropdown('dropdown1'), style={'width':'20%'}),
html.Br(),
html.Div(get_dropdown('dropdown2'), style={'width':'20%'}),
html.Br(),
html.Div(get_dropdown('dropdown3'), style={'width':'20%'}),
])
@app.callback(
Output('dropdown1', 'options'),
Output('dropdown2', 'options'),
Output('dropdown3', 'options'),
Input('dropdown1', 'value'),
Input('dropdown2', 'value'),
Input('dropdown3', 'value'),
)
def update_options(v1, v2, v3):
#logic
if __name__ == "__main__":
app.run_server(debug=True)