Hi, I’m having trouble debugging a problem with my script because I don’t get any errors. The figure in my dash below doesn’t update when numTs=1. It works fine when numTs=2. I’ve included the head of my data too.
Code here:
import dash
import pandas as pd
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output
import plotly.graph_objects as go
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div(
html.Div([
html.H4('Real-Time Data Viewer'),
html.Label('File Path:'),
dcc.Input(id='full-filepath', value='', type='text', style={
'width': '100%',
}),
dcc.Graph(id='live-update-graph'),
dcc.Interval(
id='interval-component',
interval=5000, # in milliseconds
n_intervals=0
),
dcc.RadioItems(
id='Num-Transducers',
options=[
{'label': '1 Transducer', 'value': '1'},
{'label': '2 Transducers', 'value': '2'}
],
value='1',
labelStyle={'display': 'inline-block'}
)
])
)
@app.callback(Output('live-update-graph', 'figure'),
[Input('interval-component', 'n_intervals'),
Input('full-filepath','value'),
Input('Num-Transducers', 'value')]
)
def liveupdate(n,filepath_,numTs):
print(filepath_)
if filepath_:
df_dxd = pd.read_csv(filepath_)
df_dxd = pd.read_csv(filepath_, skiprows=8, on_bad_lines='skip')
if numTs == '2':
df_dxd.drop(df_dxd.columns[[3, 4, 6,7]], axis=1, inplace=True)
df_dxd.columns = ['Date', 'Time', 'Outlet', 'Inlet']
df_dxd['DateTime'] = pd.to_datetime(df_dxd['Date'] + " " + df_dxd['Time'])
fig = go.Figure()
fig.add_trace(go.Scatter(x=df_dxd.DateTime, y=df_dxd.Outlet,
name="Outlet"))
fig.add_trace(go.Scatter(x=df_dxd.DateTime, y=df_dxd.Inlet,
name="Inlet", yaxis = "y2"))
# Set y-axes titles
fig.update_layout(yaxis=dict(title="Outlet", titlefont=dict(color="#1f77b4"),
tickfont=dict(color="#1f77b4")),
yaxis2=dict(title="Inlet",titlefont=dict(
color="#ff7f0e"), tickfont=dict(color="#ff7f0e"),
anchor="x", overlaying="y", side="right"),
uirevision='foo'
)
if numTs == '1':
df_dxd.columns = ['Date', 'Time', 'Pressure', 'Temperature']
df_dxd['DateTime'] = pd.to_datetime(df_dxd['Date'] + " " + df_dxd['Time'])
fig = go.Figure()
fig.add_trace(go.Scatter(x=df_dxd.DateTime, y=df_dxd.Pressure,
name="Pressure"))
# Set y-axes titles
fig.update_layout(yaxis=dict(title="Pressure", titlefont=dict(color="#1f77b4"),
tickfont=dict(color="#1f77b4")),
uirevision='foo'
)
return fig
else:
fig = go.Figure(go.Scatter(x=[1], y=[1], mode='markers'))
return fig
if __name__ == '__main__':
app.run_server(debug=True)
#app.run_server(debug=True,port=300,host='10.0.100.140')
Data here:
Address: | 2 | ||
---|---|---|---|
Heise Label: | 11527 | ||
User Label: | Inlet | ||
Range: | 5000 | ||
Units: | PSI | ||
Type: | G | ||
Date | Time | Pressure | Temperature |
8/8/2023 | 10:30:03 AM | 0.2 | 68.126 |
8/8/2023 | 10:30:03 AM | 0.2 | 68.108 |
8/8/2023 | 10:30:04 AM | 0.2 | 68.126 |
8/8/2023 | 10:30:05 AM | 0.2 | 68.126 |