✊🏿 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!

Refreshing main dataframe when page is reloaded

I’ve chanced upon the following two links, but I’m still confused as to how I can refresh my dataframe everytime a user reloads the page.

Live Updates
Sharing Data between Callbacks

# Function that grabs latest data from FTP server
df = ftpfile.grabDF()

# Set app.layout as a function (Part 1): Advised in Live Updates link
def serve_layout():
    return html.Div(.......)

# Reassigning dataframe to a new variable in callback : Advised in Sharing Data between Callbacks link
@app.callback(
    [Output("pie", "figure"), Output("bar", "figure")],
    [Input("checkbox1", "value"), Input("bu-checkbox2", "value")],)
def update_output_div(valueA, valueB):
    dff = df[:]

#Set app.layout as a function (Part 2): Advised in Live Updates link
app.layout = serve_layout

But the above doesn’t work as intended, the df is not obtained from the data source upon page refresh.

What am I doing wrongly?

you need to put the data frame inside the serve_layout function :slight_smile:

Ah, I’ve seen that response of yours from another thread ( :stuck_out_tongue: did do my homework)

Is repeatedly querying the source for every callback the way to go? Or can we query once per page refresh, and work with that extract until next visit / refresh. Would that be under sharing data between callbacks?

exactly - that’s sharing between callbacks

You can do both. If you want to save the data for some time before querying the again, you would need to do some kind of caching, either client side using Dash components (e.g Store) or server side. For the latter, you could try out a decorator I recently wrote,