tl;dr: am I misunderstanding using functions for my layouts? Am I updating my data wrong?
I am working on a dashboard which I initially built as static, and am now making dynamic/live. I have built my pages as functions, so it would render with the most recently scraped data every time I go on a different page/reload.
@callback(
Output("content", "children"),
Input("url", "pathname")
)
def serve_page_content(pathname):
if pathname == '/':
return pages.Today()
elif pathname == '/dagverkoop':
return pages.Daysales()
elif pathname == '/standen':
return pages.Records()
else:
return html.P('This page does not exist!')
At intervals I run a function that runs a scraper, thus updating the DataFrames I am using in my pages. However, after scraping, the pages are what they were before, without the updated information. With some testing I did find that my DataFrames would update and all functions would run properly and the DataFrames should be globally accessible.
# 'sinkhole' is a div that is meant to be hidden
@callback(
Output('sinkhole', 'children'),
Input('interval-large', 'n_intervals'),
)
def reload_data(count):
print('Ping')
if 'testTime' not in globals():
global testTime
testTime = int(time())
if (time() - testTime) >= 30:
pages.update_all()
return html.P()
def update_all():
print('Updating...')
df_live = scrape.liverecords()
df_salesstats = scrape.salesrecords()
df_today = scrape.dayfilter(df_salesstats, currentDay)
print('Done!')
Am I misunderstanding how Dash renders layouts returned from from a function called within a callback? Or am I missing something else?