awacke1 commited on
Commit
3f79c23
1 Parent(s): de61ae8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)