I have troubles updating this graph. I don’t know why the axis are not updating and the deque list is not working properly which causes that i obtain this graph
df=pd.DataFrame()
df['patient']= [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4]
df['heart rate']=np.random.uniform(low=50, high=100, size=80)
df['respiratory rate']=np.random.uniform(low=20,high=70, size=80)
df['temperature']=np.random.uniform(low=35.7,high=40, size=80)
df['oxygen saturation']=np.random.uniform(low=80,high=100,size=80)
df['physiology']=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
df['systolic blood pressure']=np.random.uniform(low=55,high=120,size=80)
df['diastolic blood pressure']=np.random.uniform(low=30, high=95,size=80)
df['bedID']= [6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7]
df['age']=[12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
df['score']=""
rng = pd.date_range('2015-02-24', periods=80, freq='h')
df['datetime']=rng
patient_id=pd.unique(df['patient'])
f=deque()
g=deque()
@app.callback(
Output('live-update4','children'),
[Input('drop56','value'),
Input('graph_interval4','n_intervals')])
def graph_dynamic(variables8, interval):
dff=0
if variables8 is None:
raise dash.exceptions.PreventUpdate()
else:
dff=0
ff=f
gg=g
dff=df
dff=nuevoRegistro(dff,1)
ff.extend(np.array(dff.loc[dff['patient']==1][str(variables8)]))
gg.extend(dff.query('patient==1')['datetime'])
traces=go.Scatter(x=list(gg), y=list(ff), mode='lines+markers')#append
layout=go.Layout(xaxis=dict(range=[min(gg),max(gg)]),yaxis=dict(range=[min(ff),max(ff)]))
return dcc.Graph(figure=go.Figure(data=traces, layout=layout)
,style={'width':'81vh', 'height':'4', 'display':'inline-block'},animate=False)
def nuevoRegistro(df, paciente):
physiology = df.loc[df['patient']==paciente]['physiology'].values[-1]
bedID = df.loc[df['patient']==paciente]['bedID'].values[-1]
age = df.loc[df['patient']==paciente]['age'].values[-1]
score = df.loc[df['patient']==paciente]['score'].values[-1]
HR = np.random.uniform(low=50, high=100, size=1)
RR = np.random.uniform(low=20,high=70, size=1)
Temp = np.random.uniform(low=35.7,high=40, size=1)
OxS = np.random.uniform(low=80,high=100,size=1)
SBP = np.random.uniform(low=55,high=120,size=1)
DBP = np.random.uniform(low=30, high=95,size=1)
datetime = df.loc[df['patient']==paciente]['datetime'].values[-1] + pd.Timedelta(1, 'h')
df_aux = pd.DataFrame([[paciente, HR[0], RR[0],Temp[0], OxS[0], physiology, SBP[0], DBP[0], bedID, age, score, datetime]],
columns= df.columns
)
df = df.append(df_aux, ignore_index=True)
return df