Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,28 @@
|
|
1 |
-
|
2 |
import streamlit as st
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
radio_list,
|
22 |
-
index = default
|
23 |
-
)
|
24 |
-
if activity:
|
25 |
-
st.experimental_set_query_params(activity=radio_list.index(activity))
|
|
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
+
# query params exist
|
4 |
+
try:
|
5 |
+
options = ['cat', 'dog', 'mouse', 'bat', 'duck']
|
6 |
+
|
7 |
+
query_params = st.experimental_get_query_params()
|
8 |
+
query_option = query_params['option'][0] #throws an exception when visiting http://host:port
|
9 |
+
|
10 |
+
option_selected = st.sidebar.selectbox('Pick option',
|
11 |
+
options,
|
12 |
+
index=options.index(query_option))
|
13 |
+
if option_selected:
|
14 |
+
st.experimental_set_query_params(option=option_selected)
|
15 |
+
|
16 |
+
# run when query params don't exist. e.g on first launch
|
17 |
+
except: # catch exception and set query param to predefined value
|
18 |
+
options = ['cat', 'dog', 'mouse', 'bat', 'duck']
|
19 |
+
st.experimental_set_query_params(option=options[1]) # defaults to dog
|
20 |
+
|
21 |
+
query_params = st.experimental_get_query_params()
|
22 |
+
query_option = query_params['option'][0]
|
23 |
|
24 |
+
option_selected = st.sidebar.selectbox('Pick option',
|
25 |
+
options,
|
26 |
+
index=options.index(query_option))
|
27 |
+
if option_selected:
|
28 |
+
st.experimental_set_query_params(option=option_selected)
|
|
|
|
|
|
|
|
|
|