Hi,
Im trying to create a live chart which updates every three seconds. Initially on loading the page the chart is blank and despite showing a basic layout.
Then, the first graph loaded looks perfectly fine.
However, on the second load the layout adjusts, but no bars are shown.
I have tried some variations but nothing seemed to have worked. I am also not getting any error message. The console only prints:
127.0.0.1 - - [16/Aug/2018 13:02:38] “POST /_dash-update-cPreformatted text
omponent HTTP/1.1” 200 -
This the entire code:
import pandas as pd
import datetime
import dashboard_module as dm
import collections
import dash
from dash.dependencies import Input,Output, Event
import dash_core_components as dcc
import dash_html_components as html
import plotly
import plotly.graph_objs as go
# df = dm.return_all_pd_data(token = API_TOKEN)
df = pd.read_pickle("/Users/dpaul/Desktop/pickle")
i = collections.deque([1,2,3,4,5,6])
app = dash.Dash()
app.layout = html.Div(
[
dcc.Graph(id='live-graph', animate=True),
dcc.Interval(
id='graph-update',
interval=3000
),
]
)
@app.callback(Output('live-graph', 'figure'),
events=[Event('graph-update', 'interval')])
def update_graph():
i.rotate()
month = i[0]
start = datetime.datetime(2018, month, 1, 0, 0, 0, 1)
end = datetime.datetime(2018, month+1, 1, 0, 0, 0, 1)
subset_df = df[ (df["lost_time"] > start) & (df["lost_time"] < end) ]
x = pd.value_counts(subset_df.deal_source).index
y = pd.value_counts(subset_df.deal_source).values
data = plotly.graph_objs.Bar(
x=x,
y=y,
name='Barchart'
)
return {'data': [data],'layout' : go.Layout(xaxis=dict(range=[min(x),max(x)]),
yaxis=dict(range=[min(y),max(y)]))}
if __name__ == "__main__":
app.run_server(debug = True)