-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathstreamlit_app.py
More file actions
95 lines (81 loc) · 2.79 KB
/
Copy pathstreamlit_app.py
File metadata and controls
95 lines (81 loc) · 2.79 KB
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
90
91
92
93
94
95
import streamlit as st
import backend as be
import ui
import visualizations as viz
st.title("How has Covid changed America?")
st.write("Explore how US demographics have changed since Covid.")
trend_tab, compare_tab, ranking_tab, about_tab = st.tabs(
["📈 Trend", "🔍 Compare Years", "🏆 Ranking", "ℹ️ About"]
)
with trend_tab:
location, column = ui.location_and_demographic_block("trend")
fig = viz.get_line_graph(location, column)
st.plotly_chart(fig)
df = be.get_trend_df_styled(location, column)
st.dataframe(df, hide_index=True)
st.caption("Tip: click a column header to sort.")
with compare_tab:
years = be.get_years()
col1, col2, col3, col4 = st.columns([35, 35, 15, 15])
with col1:
location = ui.location_selector("compare")
with col2:
column = ui.demographic_selector("compare")
with col3:
year1 = st.selectbox("First Year:", years, years.index(2019))
with col4:
year2 = st.selectbox("Second Year:", years, years.index(2021))
if year1 == year2:
st.warning("Please select two different years.")
else:
fig = viz.get_compare_scatterplot(year1, year2, column, location)
st.plotly_chart(fig)
df = be.get_compare_df_styled(year1, year2, column)
st.dataframe(df, hide_index=True)
with ranking_tab:
years = be.get_years()
col1, col2, col3 = st.columns([40, 40, 20])
with col1:
location = ui.location_selector("ranking")
with col2:
options = be.get_demographic_statistics()
column = st.selectbox(
"Demographic:",
options=options,
index=options.index("Median Household Income"),
)
with col3:
year = st.selectbox("Year:", years, len(years) - 1)
col_n, col_s, col_c, col_p = st.columns(4)
with col_n:
include_nation = st.checkbox("Nation", True)
with col_s:
include_states = st.checkbox("States", True)
with col_c:
include_counties = st.checkbox("Counties", True)
with col_p:
include_places = st.checkbox("Cities", True)
if sum([include_nation, include_states, include_counties, include_places]) == 0:
st.warning("Please select at least one geography.")
else:
fig = viz.get_single_year_scatterplot(
year,
column,
location,
include_nation,
include_states,
include_counties,
include_places,
)
st.plotly_chart(fig)
df = be.get_table_df_styled(
year,
column,
include_nation,
include_states,
include_counties,
include_places,
)
st.dataframe(df, hide_index=True)
with about_tab, open("about.md") as about_file:
st.write(about_file.read())