Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

dcc.Store - write and read a DataFrame

I use the dcc.Store Component in my Dash. The idea is to store DB-Data for a Graph-Components.
Here the declaration:

app.layout = html.Div(
     # The memory store reverts to the default on every page refresh
    dcc.Store(id='memory', storage_type = 'memory'),
     # header

I read the Data in a callback and store the Data:

@app.callback(Output('memory', 'data'),
              Input("steam-update", "n_intervals"),
              State('memory', 'data'))
def gen_global_dataframe(data):
    dt_start = + timedelta(hours=-1)
    dt_end =
    Fabrik = '001F30120E.PV' 
    data = get_steam_data(dt_start, dt_end, Fabrik)

    return data.to_dict('records')

How can I read the Data from Storage into a DF in a second callback? I try this here, but df is empty…?

    Output("steam-graph", "figure"), 
    Input("steam-update", "n_intervals"),
    State('memory', 'data')
def gen_steam_consumption(interval, data):

    df = data


Hi @Torsten,

I imagine “stream-update” refers to a dcc.Interval() component, right…?

You shouldn’t use it in your second callback. Try this instead:

    Output("steam-graph", "figure"), 
    Input('memory', 'data')
def gen_steam_consumption(data):

    df = pd.DataFrame(data)

This callback will be triggered every time the data get update, if the other callback is right (i.e. you do import a non-empty df with the function). data in this callback is a dictionary, so you have to transform to df as well.

Hope that this helps!

Hi @jlfsjunior ,

Thanks for your post. Now it works fine :slight_smile:

Best Regards