【发布时间】:2021-12-03 07:55:40
【问题描述】:
我的页面上有一堆动态生成的按钮,我想用与按钮匹配的适当帐户填写下拉列表。 我的下拉菜单在布局中是这样设置的
dcc.Dropdown(id='spread-order-buy-account',
options=[{'label': k, 'value': k.lower()} for k in ACCOUNT_CHOICES])
和
dcc.Dropdown(id='spread-order-sell-account',
options=[{'label': k, 'value': k.lower()} for k in ACCOUNT_CHOICES])
我的回调设置如下
@app.callback([Output('spread-order-buy-account', 'value'),
Output('spread-order-sell-account', 'value')],
Input({'type': 'symbol-button', 'index': ALL}, 'n_clicks'),
State('global-spreader-investor', 'active_tab'),
prevent_initial_callback=True)
def fill_accounts(*args):
states = dash.callback_context.triggered
if len(states) and states[0]['value']:
clickedElement = json.loads(states[0]['prop_id'].rsplit(".",1)[0])['index']
if (isinstance(clickedElement, str)):
theRow = df[df['symbol'] == clickedElement]
buy_account, sell_account = choose_best_accounts(theRow, args[1])
return buy_account, sell_account
return dash.no_update
输入symbol-button 可以是许多中的任何一个,它们都与买卖账户相关联,在choose_best_accounts(theRow, investor) 中适当地检索。
我已确认该函数到达返回行,其中 buy_account 和 sell_account 匹配当前填充在下拉列表中的选项,但是当我运行它时它们没有显示。
【问题讨论】:
标签: python callback plotly-dash