# New visitors don't see updated dashboard

**URL:** <https://community.plotly.com/t/new-visitors-dont-see-updated-dashboard/78902>\
**Category:** Dash Python\
**Created:** [September 29, 2023, 6:40pm UTC](https://community.plotly.com/t/new-visitors-dont-see-updated-dashboard/78902 "2023-09-29T18:40:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![celal](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@celal](https://community.plotly.com/u/celal)\
**Post date:** [September 29, 2023, 6:40pm UTC](https://community.plotly.com/t/new-visitors-dont-see-updated-dashboard/78902/1 "2023-09-29T18:40:43Z")

</div>

```auto
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.

---

<div class="post-metadata">

**Author:** ![adamschroeder](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/adamschroeder/32/17280_2.png) [@adamschroeder](https://community.plotly.com/u/adamschroeder)\
**Post date:** [September 29, 2023, 6:55pm UTC](https://community.plotly.com/t/new-visitors-dont-see-updated-dashboard/78902/2 "2023-09-29T18:55:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![celal](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@celal](https://community.plotly.com/u/celal)\
**Post date:** [September 29, 2023, 7:10pm UTC](https://community.plotly.com/t/new-visitors-dont-see-updated-dashboard/78902/3 "2023-09-29T19:10:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [September 29, 2023, 7:32pm UTC](https://community.plotly.com/t/new-visitors-dont-see-updated-dashboard/78902/4 "2023-09-29T19:32:14Z")

</div>

What is dfc, where does this come from?

---

<div class="post-metadata">

**Author:** ![celal](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@celal](https://community.plotly.com/u/celal)\
**Post date:** [September 29, 2023, 7:35pm UTC](https://community.plotly.com/t/new-visitors-dont-see-updated-dashboard/78902/5 "2023-09-29T19:35:45Z")

</div>

Updated dashboard vs. the initial dashboard (first version) after the refresh.  
 ![table346](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/1/2/1221ade99d9be9b26a414c9639c2b5440155fa4f.gif)

---

<div class="post-metadata">

**Author:** ![celal](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@celal](https://community.plotly.com/u/celal)\
**Post date:** [September 29, 2023, 7:37pm UTC](https://community.plotly.com/t/new-visitors-dont-see-updated-dashboard/78902/6 "2023-09-29T19:37:07Z")

</div>

It is a custom calendar that i use.

```auto
  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

```

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [September 29, 2023, 7:45pm UTC](https://community.plotly.com/t/new-visitors-dont-see-updated-dashboard/78902/7 "2023-09-29T19:45:20Z")

</div>

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

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![celal](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@celal](https://community.plotly.com/u/celal)\
**Post date:** [September 29, 2023, 7:59pm UTC](https://community.plotly.com/t/new-visitors-dont-see-updated-dashboard/78902/8 "2023-09-29T19:59:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![celal](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@celal](https://community.plotly.com/u/celal)\
**Post date:** [September 30, 2023, 7:47am UTC](https://community.plotly.com/t/new-visitors-dont-see-updated-dashboard/78902/9 "2023-09-30T07:47:54Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [September 30, 2023, 8:08am UTC](https://community.plotly.com/t/new-visitors-dont-see-updated-dashboard/78902/10 "2023-09-30T08:08:51Z")

</div>

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.
