awacke1 commited on
Commit
30ede3e
·
1 Parent(s): 3f1c4a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -29
app.py CHANGED
@@ -5,45 +5,33 @@ import numpy as np
5
  import altair as alt
6
  import pydeck as pdk
7
 
8
-
9
- def create_sessionmaker():
10
- a=1
11
-
12
- @st.experimental_singleton
13
- def get_database_session(_sessionmaker, url):
14
- # Create a database connection object that points to the URL.
15
- return connection
16
-
17
- s1 = get_database_session(create_sessionmaker(), st.session_state.qp)
18
- # Actually executes the function, since this is the first time it was
19
- # encountered.
20
-
21
- s2 = get_database_session(create_sessionmaker(), st.session_state.qp)
22
- # Does not execute the function. Instead, returns its previously computed
23
- # value - even though the _sessionmaker parameter was different
24
- # in both calls.
25
-
26
 
27
  # callback to update query param on selectbox change
28
  def update_params():
29
  st.experimental_set_query_params(option=st.session_state.qp)
30
- get_database_session(st.session_state.qp)
31
 
32
- options = st.selectbox(
33
- "Param", ["cat", "dog", "mouse", "bat", "duck"], key="qp", on_change=update_params
34
- )
35
 
36
  query_params = st.experimental_get_query_params()
37
 
38
- # set the initial query param on first run
39
- # based on the default option in selectbox
40
- if not query_params:
41
- st.experimental_set_query_params(option=st.session_state.qp)
 
 
 
42
 
43
- # display for debugging purposes
44
- query_params = st.experimental_get_query_params()
45
- st.write(query_params)
 
 
 
46
 
 
 
47
 
48
 
49
  # SETTING PAGE CONFIG TO WIDE MODE AND ADDING A TITLE AND FAVICON
 
5
  import altair as alt
6
  import pydeck as pdk
7
 
8
+ import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  # callback to update query param on selectbox change
11
  def update_params():
12
  st.experimental_set_query_params(option=st.session_state.qp)
 
13
 
14
+ options = ["cat", "dog", "mouse", "bat", "duck"]
 
 
15
 
16
  query_params = st.experimental_get_query_params()
17
 
18
+ # set selectbox value based on query param, or provide a default
19
+ ix = 0
20
+ if query_params:
21
+ try:
22
+ ix = options.index(query_params['option'][0])
23
+ except ValueError:
24
+ pass
25
 
26
+ selected_option = st.radio(
27
+ "Param", options, index=ix, key="qp", on_change=update_params
28
+ )
29
+
30
+ # set query param based on selection
31
+ st.experimental_set_query_params(option=selected_option)
32
 
33
+ # display for debugging purposes
34
+ st.write('---', st.experimental_get_query_params())
35
 
36
 
37
  # SETTING PAGE CONFIG TO WIDE MODE AND ADDING A TITLE AND FAVICON