问题描述
我正在尝试创建一个包含 8 个按钮的仪表板,每个按钮对应一个过滤后的 df 和 4 个下拉菜单。尝试根据触发按钮获取过滤后的 df,并使用 df 的 4 列作为 4 个不同 dcc.dropdown 的“选项”。但破折号显示此错误消息:
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.
我的回调是:
@app.callback([Output('MBD','options'),Output('Urbanity',Output('Outlet',Output('Chain','options')],[Input('all','id'),Input('fmcg',Input('bev',Input('tob',Input('food',Input('drug',Input('liquor',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]
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)