Black Lives Matter. Please consider donating to Black Girls Code today.

Update Dash Core Component Dropdown options from a callback!

I am trying to update a Dropdown based on the value from another Dropdown.
It updates second dropdown for ‘treatments’ based on ‘department’ selected from first dropdown.
Here is the function i prepared to make options for second dropdown.

def get_diseases_from_department(department_input):
        # take copy of dataframe to avoid 'SettingwithCopyWarning' from pandas on every operation on dataframe        
        diseases_of_department = complete_data.copy()
        # now get an array of unique treatments for the disease from the department input
        diseases_of_department = diseases_of_department.loc[(diseases_of_department.loc[:, 'Department'] == department_input)].loc[:,
        # make list for options
        diseases_of_department = [{'label': i, 'value': i} for i in diseases_of_department]
    # if an error happens with input, return empty options.
    except ValueError:
        diseases_of_department = [{'label': '', 'value': ''}]
    # return this now
    return diseases_of_department

Here is my callback that takes input from first callback and updates options of another callback:

@his_app.callback(Output(component_id='disease_input', component_property='options'),
                  [Input(component_id='department_input', component_property='value')])
def update_diseases_from_department(department_input_los):
    # getting the list of dictionaries from above function
    diseases_of_department = get_diseases_from_department(department_input=department_input_los)
    return diseases_of_department

Good morning @naveen_9697

I think this post on Dropdown updating Dropdown has the answer.

Let me know if that doesn’t help.

I referred that and tried fixing it. But, i realised that my second dropdown’s options can be updated with a callback, only when first dropdown’s multi is set to False; when i can select multiple options from my dropdown, this callback stops working right after first selection.