Closed benlindsay closed 6 months ago
Additional discussion here: https://discuss.streamlit.io/t/cookies-support-in-streamlit/16144/35
Should be fixed in 0.1.70
I am currently using the 0.1.71 but it seems that the rerun triggered by calling stx.CookieManager() is still present.
Anyone else with the same issue?
I've noticed that creating the cookie manager triggers a rerun of the streamlit app, which makes it difficult to work with.
For example, with this app:
It will flash "run_count: 1" faster than the eye can see and then land immediately on "run_count: 2".
Now, if we add
time.sleep(2)
after the CookieManager() call:The rerun happens during the sleep, before the increment happens, and we land on "run_count: 1".
This rerun complicates things like buttons, since the rerun reverts the buttons state back to False. For example, with this app:
We will never see the "Button clicked" message, because the rerun is triggered by CookieManager() which takes place during the sleep, and when the rerun occurs,
st.button("Button")
is nowFalse
. To get the button click to trigger actions that occur after the CookieManager() call, we need to use session state like this (or something similar):Is this expected behavior? Is there a way to prevent the rerun? Any help would be appreciated.