I am creating an application for a private event board game table reservation manager.
Since the users need to set an username in order to create/join a table I am trying to avoid them to set it every time.
For this reason I ended up into the Streamlit Extra Component for the CookieManager and as a first attempt, I just used CookieManager for both read and write usernames and it works apart from some additional rerun that the CookieManager triggers once instantiated.
Something like:
cookie_manager = stx.CookieManager() # ← triggers a useless rerun slowing down
st.session_state[‘username’] = cookie_manager.get(“username”)
# some lines later, when the users submits the (new) username:
And this approach works like a charm in my local environment (avoiding the initial annoying rerun) and if I print the whole st.context.cookies.to_dict() I get:
Hey @Marco5, this happens because Stremalit Cloud filters some headers and almost all cookies in the proxy layer. So, this is expected behavior when deployed on the Cloud.
Hello, thanks for the fast reply.
But if “Stremalit Cloud filters some headers and almost all cookies” how come CookieManager from Streamlit Extra Component works as expected in the Stremalit Cloud too (apart from the above mentioned additional rerun)?
Do you mean that the filter is performed at st.context.cookies layer?
And if so, since all the cookies are filtered out, what st.context.cookies can be used for in the Stremalit Cloud?
But if “Stremalit Cloud filters some headers and almost all cookies” how come CookieManager from Streamlit Extra Component works as expected in the Stremalit Cloud too (apart from the above mentioned additional rerun)?
I don’t know, but I assume that the CookieManager custom component reads cookie information in the front end and sends that data to the back end.
In the case of st.context, we directly read information about headers /cookies from the request, and the filtering happens before the information reaches the Streamlit app backend.
And if so, since all the cookies are filtered out, what st.context.cookies can be used for in the Stremalit Cloud?
At least right now it couldn’t be used for apps deployed on Community Cloud (and thanks for flagging this, we will mention it in documentation)!
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.