I would like to update my Dash data_table based on an interval. It will run but nothing is updating. I don’t think this should be hard but I am clearly missing something. Here is what I have:
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import dash_table
import time
import pandas as pd
def getData():
"""
Only can hit api every 6 seconds for 14 total items,
which is relevant towards the Dash interval
"""
df = pd.DataFrame()
for item in list:
data = *hit api*
df.append(data)
time.sleep(7)
return df
app = dash.Dash(__name__)
# passing in just column names to avoid needlessly hitting API
tblcols=[{'name': 'col1', 'id': 'col1'},
{'name': 'col2', 'id': 'col2'},
{'name': 'col3', 'id': 'col3'}
]
app.layout = html.Div([
html.H4('Dashboard Name'),
dcc.Interval('graph-update',interval = 500000, n_intervals = 0),
dash_table.DataTable(
id = 'table',
data = [{}],
columns=tblcols )])
@app.callback(
Output('table','data'),
[Input('graph-update', 'n_intervals')]
)
def updateTable(n):
"""
calling the get data function
"""
updated_data = getData()
return updated_data.to_dict('records')
if __name__ == '__main__':
app.run_server(debug=False)
Again, this will run and return the column headers which I pass but when I see that the update has ran in Console "“POST /_dash-update-component HTTP/1.1"”, nothing changes