【问题标题】:Fill Dash-core-component dropdown with a choice based on a button press使用基于按钮按下的选项填充 Dash-core-component 下拉列表
【发布时间】: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_accountsell_account 匹配当前填充在下拉列表中的选项,但是当我运行它时它们没有显示。

【问题讨论】:

    标签: python callback plotly-dash


    【解决方案1】:

    该值最初设置为k.lower()buy_accountsell_account 也需要与 .lower() 一起返回

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-10
      • 1970-01-01
      • 2012-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多