awacke1 commited on
Commit
0b06693
1 Parent(s): f76869d

Update app.py

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