I would like user to first select an patient id from the drop down menu, that selected id will then be refreshed using dcc.Interval
to obtain his current blood pressure live in text output (real time via database).
However, I can only obtain the blood pressure of a patient but still have to refresh it by f5 for new reading pressure. How do I modify my second callback and its relevant function?
I tried lookup those tutorials but still not sure how to mash things up. Thanks.
My 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)])
])
Respective callback:
#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}'
To trigger the callback periodically, you must add the Interval
component as an input. Hence, your second callback should be
@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}'