awacke1 commited on
Commit
9323439
1 Parent(s): 0ffac8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -19
app.py CHANGED
@@ -1,22 +1,20 @@
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
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
 
2
 
3
+ # Input fields
4
+ a = st.number_input("First value", 1, 1000)
5
+ b = st.number_input("Second value", 1, 1000)
 
 
 
 
 
 
 
 
6
 
7
+ # Perform an operation, and save its result
8
+ if st.button("Compute value"):
9
+ result = a * b
10
+ st.experimental_set_query_params(my_saved_result=result) # Save value
11
+
12
+ # Retrieve app state
13
+ app_state = st.experimental_get_query_params()
14
+
15
+ # Display saved result if it exist
16
+ if "my_saved_result" in app_state:
17
+ saved_result = app_state["my_saved_result"][0]
18
+ st.write("Here is your result", saved_result)
19
+ else:
20
+ st.write("No result to display, compute a value first.")