Black Lives Matter. Please consider donating to Black Girls Code today.

Issue with browser updating with datatable updates

Currently I have an interval updated function e.g

@app.callback([Output(‘table’, ‘data’),
Output(‘table’, ‘columns’)],
[Input(‘interval-component’, ‘n_intervals’)])
def update_graph_live(n):

within this I am making calls to a database which I have set up via a trigger i.e after some time passes it will make calls to the database. I am using global variables here to do this so I know this is problematic to Dash. Example:

def update_graph_live(n):
print(‘Updating Prices…’)
global then
global trigger
global balance
global loans

if trigger is True:
    print('Updating Database.....')
    balance = balance_sql()
    loans = loans_sql()
    df = dataframe_manip(balance, loans, hi.get_base_price('XBT'),hi.get_base_price('BCH'),hi.get_base_price('ETH'),hi.get_base_price('ETHDEC'), hi.get_base_price('FLEX'),hi.get_base_price('BCHDEC'),hi.get_base_price('XBTDEC'), usdtoct_price)
    trigger = False
    now = datetime.utcnow()
    then = now+timedelta(minutes = 1.5)
if datetime.utcnow() > then:
    trigger = True

balance_sql() makes the call to the database and returns a dataframe.

Within Update_graph_live I am also making GET requests to get other information, this is occuring every time the the interval occurs.

At the end of this function I return:

return new_frame.to_dict('rows'), columns_3

which then updates a DashTable.

What the issue is, is that this will successfully update my DashTable in the browser for a time of between 30 minutes and 2 hours before it just suddenly stops updating and becomes static with no updates thanks to the GET requests I make and no updates via the database pull. However I am sure the function is running as I have prints within it. Why is it stopping after a significant amount of time.

Thank you for reading this.

Hi @FreeLand, welcome to the forum! No solution on my end, but maybe you can narrow down the diagnosis by adding print statements just before the return to display the values of all variables in your function. Also, do you use debug=True, and if yes, does the callback raise an error?

Hi, thanks for the reply. I am indeed printing my variables before the return and oddly it continues to do so without updating my table. Also I have debug set to true - but no errors appear when it stops updating. A bit lost as to what to do.