-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
89 lines (68 loc) · 2.92 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import streamlit as st
from example.ui.components import authenticator
from example.utils import url_serde
@st.dialog("Share")
def share(path: str) -> None:
state = st.session_state.to_dict()
state_encoded = url_serde.encode(state)
st.write("Copy the link below to share the current state of the app:")
st.link_button("Share", f"{path}?s=${state_encoded}", icon=":material/link:")
st.write("Current state:")
st.json(state)
# Very limited state management, no versioning, no validation
if "s" in st.query_params:
state_decoded = url_serde.decode(st.query_params["s"])
st.session_state.update(state_decoded)
if "logged_in" not in st.session_state:
st.session_state["logged_in"] = False
about = """
This project demonstrates how to leverage the built-in power of Streamlit using best software engineering practices
and tools.
It provides a non-trivial Streamlit application skeleton, showcasing how to effectively utilize Streamlit's
capabilities and address its limitations.
See [README](https://github.com/mkuthan/example-streamlit/blob/main/README.md) for more details.
"""
get_help = "https://discuss.streamlit.io/t/non-trivial-application-skeleton-from-seasoned-software-data-engineer/86072"
report_bug = "https://github.com/mkuthan/example-streamlit/issues/new"
st.set_page_config(
page_title="Streamlit Non-Trivial App",
page_icon="https://streamlit.io/images/brand/streamlit-mark-color.png",
layout="wide",
initial_sidebar_state="auto",
menu_items={
"About": about,
"Get Help": get_help,
"Report a bug": report_bug,
},
)
st.logo("https://streamlit.io/images/brand/streamlit-logo-primary-colormark-darktext.png", size="large")
# Reduce top padding from 5rem to 2rem
st.markdown(
"""
<style>
section.stMain .block-container {
padding-top: 2rem;
}
</style>""",
unsafe_allow_html=True,
)
if not st.session_state.logged_in:
login_page = st.Page("example/ui/pages/login_page.py", title="Log in", icon=":material/login:")
current_page = st.navigation(pages=[login_page])
else:
home = st.Page("example/ui/pages/home_page.py", title="Home", icon=":material/home:", default=True)
ny_tlc_trips_totals = st.Page(
"example/ui/pages/ny_tlc_trips_totals_page.py", title="NY Taxi Trips Totals", icon=":material/local_taxi:"
)
ny_tlc_trips_count = st.Page(
"example/ui/pages/ny_tlc_trips_count_page.py", title="NY Taxi Trips Count", icon=":material/analytics:"
)
ny_tlc_trips_avg_speed = st.Page(
"example/ui/pages/ny_tlc_trips_avg_speed_page.py", title="NY Taxi Trips Avg Speed", icon=":material/speed:"
)
current_page = st.navigation(pages=[home, ny_tlc_trips_totals, ny_tlc_trips_count, ny_tlc_trips_avg_speed])
if st.sidebar.button("Share", icon=":material/link:"):
share(current_page.url_path)
if st.sidebar.button("Log out", icon=":material/person:"):
authenticator.logout()
current_page.run()