Is there a way to keep data persistent after page reload?

I am looking for a way to keep some data (strictly speaking only two values) persistent even after a page reload. I guess this page reload inits a new session !?!?

I’ve found some cookie solutions but so far these all seems not persistent after page reloading.

Is there any solution?

1 Like

You can use the session_state. :slight_smile:
EDIT : My bad, i though it was a rerun.

mhmmm, but session_state is not persistent for a page reload as this results in a new session id.

Hi dirk,

Where is this streamlit app running? Knowing this would help inform available options.

I think your best options are to:

  1. save it to some sort of file/db/key value store depending on where this app is running
  2. look into how others have handled using cookies such as New Component: Streamlit-Cookies-Controller
2 Likes

This is what I do. Depending on the data you need to be persistent I either load it from a DB or use the cookie controller.

1 Like

The app is deployed in our intranet as Docker Container.

But regarding the cookie solitions I found, those are not persistent for page reloads.

Or I have been experienced non-compabilities with the integration of the keycloak package which results in not be able to get a correct login token.

I’ve found the cookies components to be somewhat tricky to use reliably for things like this, but I would recommend considering connecting to a database of some sort – here are some examples Connect to data sources - Streamlit Docs

Would it be sufficient for you to store the data in your internal filesystem, i.e. from where you’re deploying the docker container? In that case, you could mount a volume in docker (mapping a directory in your filesystem to a directory in the docker container). This way your docker output data would persist in your local filesystem.