Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from streamlit_cookies_manager import EncryptedCookieManager
|
| 4 |
+
|
| 5 |
+
# This should be on top of your script
|
| 6 |
+
cookies = EncryptedCookieManager(
|
| 7 |
+
# This prefix will get added to all your cookie names.
|
| 8 |
+
# This way you can run your app on Streamlit Cloud without cookie name clashes with other apps.
|
| 9 |
+
prefix="ktosiek/streamlit-cookies-manager/",
|
| 10 |
+
# You should really setup a long COOKIES_PASSWORD secret if you're running on Streamlit Cloud.
|
| 11 |
+
password=os.environ.get("COOKIES_PASSWORD", "My secret password"),
|
| 12 |
+
)
|
| 13 |
+
if not cookies.ready():
|
| 14 |
+
# Wait for the component to load and send us current cookies.
|
| 15 |
+
st.stop()
|
| 16 |
+
|
| 17 |
+
st.write("Current cookies:", cookies)
|
| 18 |
+
value = st.text_input("New value for a cookie")
|
| 19 |
+
if st.button("Change the cookie"):
|
| 20 |
+
cookies['a-cookie'] = value # This will get saved on next rerun
|
| 21 |
+
if st.button("No really, change it now"):
|
| 22 |
+
cookies.save() # Force saving the cookies now, without a rerun
|