Python 如何对所选下拉值应用dcc间隔

Python 如何对所选下拉值应用dcc间隔,python,plotly,dashboard,plotly-dash,Python,Plotly,Dashboard,Plotly Dash,我希望用户首先从下拉菜单中选择患者id,然后使用dcc.Interval刷新所选id,以获取其当前血压实时文本输出(通过数据库实时) 但是,我只能获取患者的血压,但仍需按f5刷新以获取新的读数压力。 如何修改第二个回调及其相关函数 我试着查找那些教程,但仍然不确定如何将它们混合起来。谢谢 我的应用程序布局: app.layout = html.Div([ html.Div([dcc.Dropdown(id='dropdown',

我希望用户首先从下拉菜单中选择患者id,然后使用
dcc.Interval
刷新所选id,以获取其当前血压实时文本输出(通过数据库实时)

但是,我只能获取患者的血压,但仍需按f5刷新以获取新的读数压力。 如何修改第二个回调及其相关函数

我试着查找那些教程,但仍然不确定如何将它们混合起来。谢谢

我的应用程序布局

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}'
各自的回调

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}'

要定期触发回调,必须添加
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}'