I was trying to create a line graph in Dash. It is returning an empty graph with a tick mark and axis.
I created the same graph only in plotly. it works fine.
Please help me to figure out what am I doing wrong
Here’s what I want:
but this is what I end up getting:
Here’s a screenshot of the data:
And here’s my code:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import plotly.graph_objs as go
import pandas as pd
#create dataframe
data_line_current = pd.read_csv(‘AR_LINE_CUR.csv’)
#print (data_line_current.head())
app= dash.Dash()
app.layout = html.Div(
[
#graph start
dcc.Graph(id=‘graph’),
#graph start
]
)
@app.callback(
Output(‘graph’,‘figure’)
)
def update_figure():
#filter data_line_current to only selected date
traces = []
for meter_no in filtered_df[u’meter_no’].unique():
df_by_meter = filtered_df[filtered_df[u’meter_no’]==meter_no]
traces.append(go.Scatter
(
x=data_line_current['cur_reading_time'],
y=data_line_current['Avg_Line_Current'],
mode='lines'
#name=meter_no,
)
)
return {
'data':traces ,
'layout':go.Layout(
title = 'My Plot',
xaxis = {'title':'Reading Date & Time'},
yaxis = {'title':'Avg Line Current'}
)
}
if name==‘main’:
app.run_server()