Problems persisting state between pages

Many components such as the dropdown support the persistence argument to persist the state of the dropdown even if one switches between pages of a multi-page application. However, I couldn’t manage to persist things such as a DataTable although it also allows to define the persistence keyword. Does anyone know a convenient way to persist datatables or even the state of a whole page such that one does not have to reload everything whenever s/he switched between pages?
Do I have to use somethings like redis or Flask-Caching to do so or does Dash itself provide a convenient way to do so?

Thanks in advance!

1 Like

@MoDo I have exactly the same issue here. I try to keep data and columns persistent when switching tabs. For doing so I set the following properties of the DataTable:

        persisted_props=["data", ""],

This doesn’t do any good and my DataTable will always be empty after switching tabs. :frowning: Did you make any progress on this issue?

Did you try using another persistence_type? Other possible values are local and memory (see here).

Not sure if that will really help, but it won’t hurt to try.

@MichelH I tried all three types of persistence types. None of them worked for me. But there is a workaround: Using a Store component with storage_type="session" works for me:

layout = html.Div([
    dcc.Store(id="store", storage_type="session"),

    Output("store", "data"),
    Input("upload", "contents"),
def update_store(contents):
    if contents is None:
        raise PreventUpdate

    content_type, content_string = contents.split(",")
    decoded = base64.b64decode(content_string)

        df = pd.read_excel(io.BytesIO(decoded))
    except Exception as e:
        return "Error"

    data = df.to_dict("records")
    columns = [{"name": i, "id": i} for i in df.columns]

    return {"data": data, "columns": columns}

    Output("datatable", "data"),
    Output("datatable", "columns"),
    Input("store", "modified_timestamp"),
    State("store", "data"),
def update_datatable(modified_timestamp, store_data):
    if store_data is None:
        raise PreventUpdate

    return store_data["data"], store_data["columns"]

But as described in the docs using the persistence property should actually work find with DataTables:

Persistence is supported by dash-table and all the form-like components in dash-core-components .