Skip to content

Commit

Permalink
update the load_uuids_stats callback
Browse files Browse the repository at this point in the history
Not having an Output caused this to be executed upon loading the dashboard, before we are even on the Data page.
Added store-loaded-uuids as the Output

This causes the loading spinner to not go away, because dash is 'waiting' for the Output. We can manually hide it after and reinstate it when the callback stops running by using the `running=` param

Also, make this callback cancelable. Anytime the tab changes, if we were running the callback we can stop that call.
  • Loading branch information
JGreenlee committed Dec 17, 2024
1 parent 9ee3ef5 commit f9c0c8f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pages/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,16 @@ def update_uuids_page_current(page_current, selected_tab):
raise PreventUpdate

@callback(
Output('store-loaded-uuids', 'data'),
Input('tabs-datatable', 'value'),
Input('store-uuids', 'data'),
background=True,
# when the callback initializes, set the spinner to 'auto' allowing it to show
# after a batch loads, we set it to 'hide' (see below)
# when the callback finishes or cancels, we'll set it back to 'auto'
running=[Output('global-loading', 'display'), 'auto', 'auto'],
# if tabs-datatable changes at all while callback is running, cancel
cancel=[Input('tabs-datatable', 'value')],
)
def load_uuids_stats(tab, uuids):
logging.debug("loading uuids stats for tab %s" % tab)
Expand All @@ -158,10 +165,10 @@ def load_uuids_stats(tab, uuids):
processed_uuids = db_utils.add_user_stats(uuids, 10)
loaded_uuids.extend(processed_uuids)
logging.debug("loaded %s uuids stats: %s" % (len(loaded_uuids), loaded_uuids))
set_props(
"store-loaded-uuids",
{ "data": loaded_uuids }
)
# after each chunk, update the store and hide the spinner
set_props( "store-loaded-uuids", {"data": loaded_uuids})
set_props("global-loading", {"display": "hide"})
return loaded_uuids

@callback(
Output('tabs-content', 'children'),
Expand Down

0 comments on commit f9c0c8f

Please sign in to comment.