✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Mixed callback with interval and dropdown

i have a working app that uses a dropdown menu to allow users to select from a range of different plots for a reporting dashboard, and everything is working well, but i need some help understanding how to properly use the dcc.Interval functionality.

the use case is as follows: i have a cron job (ubuntu) running 4 times a day to do some ETL work (parsing log files) and then batch updating two database tables. in my dash app, this database is queried to make two dataframes which are passed to an update_graph() function when a dropdown item is selected. i would like to use the dcc.Interval to auto-update these dataframes, but i do not want the dataframes to update every time a dropdown item is selected. so i have two questions:

  1. how can i access the n_intervals counter of the dcc.Interval so i can compare the current value to the last value to trigger the database queries? it seems this would require keeping a global variable corresponding to the old value, so maybe this is not the right way to think about this?
  2. i’ve found some posts claiming the way to do this is to either write the updated dataframes to disk and read them as part of the callback, or to pass them around as a local data object… is this really the best method?

thanks!
liam