如何在选定的下拉值上应用dcc间隔

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

我希望用户首先从下拉菜单中选择一个患者ID,然后使用以下方法刷新该ID dcc.Interval 来获取他当前的血压实时文本输出(通过数据库实时)。

但是,我只能获得一个病人的血压,但仍然要通过f5刷新新的读数压力,我如何修改我的第二个回调和它的相关功能?

我试着查了那些教程,但还是不知道怎么捣鼓。谢谢。

我的 app.布局:

app.layout = html.Div([

                html.Div([dcc.Dropdown(id='dropdown',
                                    options=[{'label': i, 'value': i} for i in x],
                                    value='x',
                                    clearable=False),
                        html.Div(id='table-container')]),

                html.Div([html.Div(id='live-update-text'),
                          dcc.Interval(id='interval-component', interval=2000, n_intervals=0)])

])

相关回调:

#First callback and its function [working as expected]
@app.callback(
    dash.dependencies.Output('dropdown', 'options'),
    [dash.dependencies.Input('dropdown', 'value')])
def get_update_db_dropdown(value):
    #connect to database and then return the results.

#Second callback and its pseudo function; I want this to be self refresh/live updating via dcc interval process
@app.callback(
    Output('live-update-text', 'children'),
    [dash.dependencies.Input('dropdown', 'value')])
def set_display_livedata(value):
    #connect to database and obtain blood pressure where id=value
    return f'selected {id} has {bloodPressure}'
python plotly dashboard plotly-dash
1个回答
1
投票

要周期性地触发回调,你必须在下面的函数中添加 Interval 组件作为输入。因此,你的第二个回调应该是

@app.callback(
    Output('live-update-text', 'children'),
    [dash.dependencies.Input('dropdown', 'value'), dash.dependencies.Input('interval-component', 'n_intervals')])
def set_display_livedata(value, n_intervals):
    #connect to database and obtain blood pressure where id=value
    return f'selected {id} has {bloodPressure}'
© www.soinside.com 2019 - 2024. All rights reserved.