如何在选定的下拉值上应用 dcc 间隔
how to apply dcc interval on the selected drop down value
我希望用户首先从下拉菜单中 select 一个患者 ID,然后 selected id 将使用 dcc.Interval
刷新以获得他当前的实时血压在文本输出中(通过数据库实时)。
但是,我只能得到一个病人的血压,但仍然需要按f5刷新它以获得新的读数压力。
如何修改我的第二个回调及其相关函数?
我尝试查找那些教程,但仍然不确定如何将它们融合在一起。谢谢
我的app.layout:
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}'
我希望用户首先从下拉菜单中 select 一个患者 ID,然后 selected id 将使用 dcc.Interval
刷新以获得他当前的实时血压在文本输出中(通过数据库实时)。
但是,我只能得到一个病人的血压,但仍然需要按f5刷新它以获得新的读数压力。 如何修改我的第二个回调及其相关函数?
我尝试查找那些教程,但仍然不确定如何将它们融合在一起。谢谢
我的app.layout:
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}'