Black Lives Matter. Please consider donating to Black Girls Code today.

Dynamic update using CSV

Hi Guys,

Completely new to dash!

I can’t figure out for the life of me how to do a live graph which is updating from a csv file. I am using python to generate data and writing that data to a csv with 2 columns, time and response.

The csv will be generated with real httploadtime values using a raspberry pi eventually, until then for testing purposes I am generating a random number ranging from 0.1 to 0.9 for the yaxis and just using a counter for the xaxis.

The problem it will only graph that data that the csv has on the time of running and wont update with the CSV.

I have been tweeking the code for about a week now with no luck, I appreciate any help to get it working.

my code is the following:

import dash
from dash.dependencies import Output, Input
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objects as go

app = dash.Dash(name)
df = pd.read_csv(‘httploadtime.csv’)
x =
y =

app.layout = html.Div(
[
html.H1(‘HTTP LOAD TIME’),
dcc.Graph(id=‘live-update-graph’, animate=True),
dcc.Interval(
id=‘interval-component’,
interval=1000, # in milliseconds
n_intervals=0
)
])

@app.callback(Output(‘live-update-graph’, ‘figure’),
[Input(‘interval-component’, ‘n_intervals’)]
)
def update_graph_live(n):
data = {
‘time’:,
‘response’:
}
for index, rows in df.iterrows():
x = [rows.Time]
y = [rows.Response]
fig = go.Figure(data=[
go.Scatter(x=x,
y=x,
name=‘HTTP load time’,
mode = ‘lines+markers’
)
])
return fig

if name == ‘main’:
app.run_server()