Save and Load User Preferences


I am wanting to have user preferences for my app which will be remembered each time the app is loaded.
I had thought I would have a preferences page with the current options and allow them to be saved.
Ideas I have for preferences are:

  1. Auto Pagination On/Off
  2. Shown AG Grid Columns
  3. Location Filter

I believe 2 & 3 could possibly be down with persistence.
I do not think 1 could be done with persistence since the auto pagination is currently controlled by a dbc.Button element.

If I had a preferences page could I use dcc.Store to save the settings and these be used when the app is loaded or refreshed?

Thank you

Hey @QSD449!

Yes, you have a couple of options for persistence in Dash. All of these can be used safely if the information being stored is not sensitive (e.g. if you don’t have to worry about XSS, CSRF attacks).

dcc.Store will store a string-type value in sessionStorage or localStorage in the browser. sessionStorage has a lifespan of a tab, localStorage has indefinitely lifespan depending on an expiration. The max storage in these types safely is about 5MiB.

You can also set a cookie in your browser and enforce httpOnly and Secure cookie requirements to make it slightly safer. You can check the values stored in the cookie to see if any user preferences have been saved. You pay the overhead of transporting the cookie along with every request, but that’s not huge.

1 Like