2021年1月28日星期四

Dash Callback function not responding; Error: Duplicate Callback Output

I am trying to create a dashboard consisting of 8 buttons, each of which corresponds to a filtered df and 4 dropdowns. The attempt was to take the filtered df according to the triggered button and use 4 columns of the df for 'options' of 4 different dcc.dropdown. But dash shows this error message:

In the callback for output(s):  MBD.options  Urbanity.options  Outlet.options  Chain.options  Output 1 (Urbanity.options) is already in use.  Any given output can only have one callback that sets it.  To resolve this situation, try combining these into  one callback function, distinguishing the trigger  by using dash.callback_context if necessary.  

My callback is:

@app.callback([Output('MBD', 'options'), Output('Urbanity', 'options'), Output('Outlet', 'options'),             Output('Chain', 'options')],             [Input('all','id'), Input('fmcg','id'), Input('bev','id'), Input('tob','id'),             Input('food','id'), Input('drug','id'), Input('liquor','id'),              Input('unilever','id')])  def update_dd(all_b, fmcg_b, bev_b, tob_b, food_b, drug_b, liq_b, unil_b):      ctx = dash.callback_context      dff = pd.DataFrame()    if not ctx.triggered:      button_id  = 'all.id'  else:      button_id = ctx.triggered[0]['prop_id']  if button_id == 'all.id' :      dff = alloutlet_df.copy()  elif button_id == 'fmcg.id':      dff = fmcg_df.copy()  elif button_id == 'bev.id':      dff = bev_df.copy()  elif button_id == 'tob.id':      dff = tob_df.copy()  elif button_id == 'food.id':      dff = food_df.copy()  elif button_id == 'drug.id':      dff = drug_df.copy()  elif button_id == 'liquor.id':      dff = liquor_df.copy()  elif button_id == 'unilever.id':      dff = unilever_df.copy()  else:      dff = df.copy()      mbd_opt = {'label':dff['Region'].unique(), 'value':dff['Region'].unique()}   urb_opt = {'label':dff['Urbanity'].unique(), 'value': dff['Urbanity'].unique()}   out_opt = {'label':dff['Outype_panel'].unique(), 'value':dff['Outype_panel'].unique()}   chain_opt = {'label':dff['CHAIN'].unique(), 'value':dff['CHAIN'].unique()}   return [mbd_opt, urb_opt, out_opt, chain_opt]  
https://stackoverflow.com/questions/65941225/dash-callback-function-not-responding-error-duplicate-callback-output January 29, 2021 at 12:26AM

没有评论:

发表评论