-
Is there a way to persist states when the user refreshes the page? Here's what I tried to do to the click example:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
There isn't an easy way to do this today. You could connect to a database/redis and then store the data there. @richard-to is working on a way to eventually back the session data to a datastore like redis. Could you tell us more about your use case? |
Beta Was this translation helpful? Give feedback.
-
Yes, as Willl mentioned, we are working on a backend state persistence improvement. It's still in the design phase, but one option we have is to use the Flask session cookie to store look up key for the state. So if we take that approach for storing the look up key, I think we would be able to reload state for the user. At the moment, I don't think there is a way for you to access the flask session object from Mesop. And there's no way to set the secret key which is required for using the flask session object. |
Beta Was this translation helpful? Give feedback.
-
I figured it out partially...
However, edits to the session WITHIN the generating code (i.e. within the Mesop app) do NOT propagate out. So somehow the subcontext's session object would need to be passed out with the response and then override the existing one in the global context (i.e. the I tested the session persistence within the ui_stream route and it works exactly as expected: each user has their own session until they close their browser or open a different browser altogether. Hope this helps! |
Beta Was this translation helpful? Give feedback.
I figured it out partially...
flask_app.secret_key = b"very_secret_key"
and the mesop script can get the flask app instance easily with the
current_app
variable:from flask import current_app
But note you can only use it within the context of a request for it to work. Not sure how to nicely set this in a Mesop script, such that the secret key can be set before any "real" sessions are started. Probably easy though by using an initial "dead" request just to open the app context so the script can get the instance and set the key...…