Hello-
I am new to Dash and Plotly but I am really enjoying the powerful capabilities and simplicity of Dash. So far I have two graphs I am really happy with but now I am trying to make them auto update on a certain schedule. From what I have gathered through google I will need to use interval but I have had no luck finding a good example to help me achieve this goal. I am likely missing something simple but I am hoping that someone will help me along so that I can make my graphs update on a certain interval as the source datasheet changes.
I think the changes I need to make are in the app.callback and subsequent function. Do I need to define the graphs within this function? I have included a snippet from one of the recipes but I am not sure how to make it work with my graphs. Any help is greatly appreciated.
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import pandas as pd
import plotly.graph_objs as go
import datetime
df = pd.read_csv(
'C:\\Users\\Chase\\Documents\\someFile.csv')
#limites rows to last week
df = df.tail(168)
#generate overall hourly averages
df.averagePerHour = (df.Goals + df.Portal+ df.Profile + df.Summary + df.Challenges + df.Past_Challenges + df.Activity_History + df.Nutrition_Data + df.My_Plan + df.My_Program + df.Videos + df.Classes + df.Events + df.Calendar + df.Home + df.Devices + df.Manage_Priority + df.Messages + df.Activity + df.Health_Log + df.Fit_Test + df.Records + df.Support + df.Nutrition)/24
#limits rows to last day
df2 = df.tail(24)
#generates dataframe containing weekly averages
df2= df2.mean().to_frame().T
#print list(df2.Portal)
app = dash.Dash()
app.layout = html.Div(id='myTabs', children=[
#html.H1(children='Dash Tutorials'),
dcc.Graph(
id='TTL Over Time',
figure={
'data': [
{'x': df.Date, 'y': df.averagePerHour, 'type': 'line', 'name': 'Hourly Average'},
],
'layout': {
'title': 'Average TTL Per Hour This Week',
'showlegend': False
}
},
),
dcc.Interval(
id='my_interval',
interval=5000, # in milliseconds
n_intervals=0
),
dcc.Input(id='input', value='Enter something here!', type='text'),
html.Div(id='output')
])
@app.callback(
Output(component_id='output', component_property='children'),
[Input(component_id='input', component_property='value')]
)
def update_value(input_data):
return 'Input: "{}"'.format(input_data)
if __name__ == '__main__':
app.run_server(debug=True)