New visitors don't see updated dashboard

def screener():
    dfx = mdivosc()  
    screener_csv = 'screener_' + str(dfc['OC'].iloc[0].strftime('%Y_%m_%d')) + '.csv'
    dfx.to_csv(screener_csv,index=False)
def get_screener():
  dfx = pd.read_csv('screener_' + str(dfc['OC'].iloc[0].strftime('%Y_%m_%d')) + '.csv')
  dfx.reset_index(drop=True)
  print(dfx.head(15))
  return dfx.to_dict('records')
def create_layout():
    return html.Div([
                dcc.Interval(id='interval', interval=900*1000, n_intervals=0),
                dag.AgGrid(rowData=get_screener(),
                        columnDefs=tblcols,
                        id="df-table",
                        ),
            ])
app.layout = create_layout
@app.callback(
    Output("df-table", "rowData"),
    Output("df-table", "columnDefs"),
    Input('interval', 'n_intervals'),
    prevent_initial_call=True,
)
def update_screener(n):
  #UPDATING
  dfx = pd.read_csv('screener_' + str(dfc['OC'].iloc[0].strftime('%Y_%m_%d')) + '.csv')
  print('UPDATING SCREENER at',dt.now())
  print(dfx.head(15))
  time.sleep(5)
  return dfx.to_dict("records"), [{"field": i} for i in dfx.columns]
scheduler = BackgroundScheduler(timezone="Europe/Berlin")
trigger = OrTrigger([CronTrigger(hour='10', minute='30-59/15'),
                     CronTrigger(hour='11-17', minute='0-59/15'),
                     CronTrigger(hour='18', minute='0-30/15'),
                     ])
scheduler.add_job(screener, trigger, run_date=dfc['OC'].iloc[0].strftime('%Y_%m_%d'),next_run_time=dt.now())
scheduler.start()

if __name__ == "__main__":
    app.run_server(debug=True)

I have a simple AgGrid dashboard. It’s getting updated from a csv file with the interval component. screener() function is scheduled to recreate that csv file at specific times.
Now i need to show updated datatable whenever someone visit or refresh the dashboard page.
However this code brings the first version of the dashboard.
I tried to use local store component. And i think because of this interval component doesn’t work on time when i deploy it as a web app. It triggers interval for all new sessions.
What i want to do is I need to serve latest dashboard for all new sessions.

hi @celal
It appears to me that the callback function is used to read the csv file every n_intervals.

What is the part the updates the csv file that you have on the server? Is it the scheduler.add_job()?

And are you 100% sure that the csv file is being updated and saved on the server?

Update works just fine. I load the same file with the layout and that is getting updated with screener function(which is scheduled). However when I visit the dashboard lets say from another browser i see the initial datatable before the updates.

edit: even if i manually edit the csv file and refresh the page i see the unedited csv file on dashboard.

What is dfc, where does this come from?

Updated dashboard vs. the initial dashboard (first version) after the refresh.
table346

It is a custom calendar that i use.

  TF  PC         AC         OC         UN        
0   D 2023-09-27 2023-09-28 2023-09-29 2023-09-29
1  3D 2023-09-19 2023-09-22 2023-09-27 2023-09-29
2   W 2023-09-11 2023-09-18 2023-09-25 2023-09-29
3  2W 2023-08-28 2023-09-11 2023-09-25 2023-10-06
4   M 2023-07-03 2023-08-01 2023-09-01 2023-09-29

What happens if you stop the scheduler? (comment that section out)

def screener():
    dfx = mdivosc()  
    screener_csv = 'screener_' + str(dfc['OC'].iloc[0].strftime('%Y_%m_%d')) + '.csv'
    dfx.to_csv(screener_csv,index=False)
def get_screener():
  dfx = pd.read_csv('screener_' + str(dfc['OC'].iloc[0].strftime('%Y_%m_%d')) + '.csv')
  dfx.reset_index(drop=True)
  print(dfx.head(15))
  return dfx.to_dict('records')
def create_layout():
    newRecords = get_screener()
    return html.Div([
                dcc.Interval(id='interval', interval=900*1000, n_intervals=0),
                dag.AgGrid(rowData=newRecords,
                        columnDefs=tblcols,
                        id="df-table",
                        ),
            ])
app.layout = create_layout
@app.callback(
    Output("df-table", "rowData"),
    Output("df-table", "columnDefs"),
    Input('interval', 'n_intervals'),
    prevent_initial_call=True,
)
def update_screener(n):
  #UPDATING
  dfx = pd.read_csv('screener_' + str(dfc['OC'].iloc[0].strftime('%Y_%m_%d')) + '.csv')
  print('UPDATING SCREENER at',dt.now())
  print(dfx.head(15))
  time.sleep(5)
  return dfx.to_dict("records"), [{"field": i} for i in dfx.columns]
scheduler = BackgroundScheduler(timezone="Europe/Berlin")
trigger = OrTrigger([CronTrigger(hour='10', minute='30-59/15'),
                     CronTrigger(hour='11-17', minute='0-59/15'),
                     CronTrigger(hour='18', minute='0-30/15'),
                     ])
#scheduler.add_job(screener, trigger, run_date=dfc['OC'].iloc[0].strftime('%Y_%m_%d'),next_run_time=dt.now())
#scheduler.start()

if __name__ == "__main__":
    app.run_server(debug=True)

Result is the same. Scheduler is a different process and i need to seperate that function from the dash as it is an expensive process and needs to run at specific times.

I commented out entire schedule section and this time it worked. I couldn’t understad how it works? Why schedule prevents other sessions to browse updated data?

My assumption is that the scheduler only runs once and somehow the dfx is only getting updated via the callback.

If you want the scheduler process to do something, then I recommend putting it into another file and running it with supervisor.