Hi all,
I have a series of chained callbacks that progressively filter options down to the last level of the chain, the value of which is then passed as an argument into the update_figure function that plots the graphs on the dashboard. However, I would like for the value of any level of the callback chain to be passed as the argument into update_figure if a specific value in the corresponding dropdown is chosen. For instance, in the code below, if the ‘pest_family’, ‘pest_genus’, or ‘pest_species’ values were to be selected from their dropdowns to be “not found”, I would want the values for ‘pest_order’, ‘pest_family’, or ‘pest_genus’, respectively, to be passed as an argument into update_figure. Is this possible? (The month and year arguments represent values passed from time sliders). Thanks for the help.
@app.callback(
Output('pest_family', 'options'),
Input('pest_order', 'value')
)
def set_pfam_options(selected_pord):
return [{'label': i, 'value': i} for i in aphis['Pest family'].loc[aphis['Pest order'] == selected_pord].unique() if i == i]
@app.callback(
Output('pest_genus', 'options'),
Input('pest_family', 'value')
)
def set_pgen_options(selected_pfam):
return [{'label': i, 'value': i} for i in aphis['Pest genus'].loc[aphis['Pest family'] == selected_pfam].unique() if i == i]
@app.callback(
Output('pest_species', 'options'),
Input('pest_genus', 'value')
)
def set_pspc_options(selected_pgen):
return [{'label': i, 'value': i} for i in aphis['Pest species'].loc[aphis['Pest genus'] == selected_pgen].unique() if i == i]
@app.callback(
Output('host_determination', 'options'),
Input('pest_species', 'value')
)
def set_host_det(selected_pspc):
return [{'label': i, 'value': i} for i in aphis['Inspected Host cleaned'].loc[aphis['Pest species'] == selected_pspc].unique() if i == i]
@app.callback(
Output('choro_plot1', 'figure'),
Output('bar_plot1', 'figure'),
Input('month_slider', 'value'),
Input('year_slider', 'value'),
Input('pest_species', 'value'),
Input('host_determination', 'value')
)
def update_figure(month, year, pspc, hspc):
filtered_df = aphis.loc[(aphis['Inspected Host cleaned'].isin([hspc])) &
(aphis['Pest species'].isin([pspc])) &
(aphis['Interception Date'].dt.year == year) &
(aphis['Interception Date'].dt.month == month)]