在 Plotly dash 应用程序中将值从回调传递到回调

问题描述 投票:0回答:1

我有一个带有绘图图的破折号应用程序,我有两个回调,我想从用户获取输入,将其与 dcc.store 一起存储在 id 为“stkName-value”的变量中,并在另一个回调中调用它。我希望能够获取用户输入并在回调函数 update_graph_live 中使用它我该怎么做请帮忙

from dash import Dash, dcc, html, Input, Output, callback, State
app = Dash()
app.layout = html.Div([
    
    dcc.Graph(id='graph'),
    dcc.Interval(
        id='interval',
        interval=inter,
        n_intervals=0,
      ),

    html.Div(dcc.Input(id='input-on-submit', type='text')),
    html.Button('Submit', id='submit-val', n_clicks=0),
    html.Div(id='container-button-basic',children='Enter a value and press submit'),

    dcc.Store(id='stkName-value')
    
    

])

@callback(
    Output('stkName-value', 'data'),
    Output('container-button-basic', 'children'),
    Input('submit-val', 'n_clicks'),
    State('input-on-submit', 'value'),
    prevent_initial_call=True
)

def update_output(n_clicks, value):
    value = str(value).upper() 
    if value in symbols:
        print('The input symbol was "{}" '.format(value))
        return str(value).upper(), str(value).upper()
    else:
        return 'The input symbol was '+str(value)+' is not accepted please try different symbol ', 'The input symbol was '+str(value)+' is not accepted please try different symbol '

@callback(Output('graph', 'figure'),
          Input('interval', 'n_intervals'))

def update_graph_live(n_intervals):
...
return figure


python callback plotly plotly-dash plotly-python
1个回答
0
投票

您也可以使用存储数据作为回调的输入。一旦商店更新,就会触发第二次回调。

@callback(Output('graph', 'figure'),
          Input('stkName-value', 'data'),
          )
def update_graph_live(data):
    ...
    return fig
© www.soinside.com 2019 - 2024. All rights reserved.