Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,69 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import pandas as pd
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
st.
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import altair as alt
|
3 |
import pandas as pd
|
4 |
+
|
5 |
+
# Title
|
6 |
+
st.title("Building Inventory Interactive Visualization")
|
7 |
+
|
8 |
+
# Load Dataset
|
9 |
+
@st.cache
|
10 |
+
def load_data():
|
11 |
+
url = "https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/building_inventory.csv"
|
12 |
+
return pd.read_csv(url)
|
13 |
+
|
14 |
+
data = load_data()
|
15 |
+
|
16 |
+
# Data Preview
|
17 |
+
if st.sidebar.checkbox("Show Raw Data"):
|
18 |
+
st.subheader("Raw Dataset")
|
19 |
+
st.dataframe(data)
|
20 |
+
|
21 |
+
# Selections
|
22 |
+
brush = alt.selection_interval(encodings=["x"])
|
23 |
+
click = alt.selection_point(encodings=["color"])
|
24 |
+
|
25 |
+
# Add color scale for 'Square Footage'
|
26 |
+
square_footage_scale = alt.Scale(scheme="blues")
|
27 |
+
color = alt.Color("Square Footage:Q", scale=square_footage_scale, title="Square Footage")
|
28 |
+
|
29 |
+
# Top Panel: Scatter Plot (Year Acquired vs Square Footage)
|
30 |
+
scatter = (
|
31 |
+
alt.Chart(data)
|
32 |
+
.mark_point()
|
33 |
+
.encode(
|
34 |
+
alt.X("Year Acquired:Q", title="Year Acquired"),
|
35 |
+
alt.Y("Square Footage:Q", title="Square Footage"),
|
36 |
+
color=alt.condition(brush, color, alt.value("lightgray")),
|
37 |
+
size=alt.Size("Total Floors:Q", scale=alt.Scale(range=[50, 300]), title="Total Floors"),
|
38 |
+
tooltip=["Agency Name", "Location Name", "Square Footage", "Year Acquired"]
|
39 |
+
)
|
40 |
+
.properties(width=550, height=300, title="Building Size by Acquisition Year")
|
41 |
+
.add_params(brush)
|
42 |
+
.transform_filter(click)
|
43 |
+
)
|
44 |
+
|
45 |
+
# Bottom Panel: Bar Chart (Square Footage Distribution by Year Acquired)
|
46 |
+
bar_chart = (
|
47 |
+
alt.Chart(data)
|
48 |
+
.mark_bar()
|
49 |
+
.encode(
|
50 |
+
x="Square Footage:Q",
|
51 |
+
y=alt.Y("Year Acquired:Q", title="Year Acquired"),
|
52 |
+
color=alt.condition(click, color, alt.value("lightgray")),
|
53 |
+
tooltip=["Square Footage", "Year Acquired"]
|
54 |
+
)
|
55 |
+
.transform_filter(brush)
|
56 |
+
.properties(width=550, title="Square Footage Distribution by Year Acquired")
|
57 |
+
.add_params(click)
|
58 |
+
)
|
59 |
+
|
60 |
+
# Combined Chart
|
61 |
+
chart = alt.vconcat(scatter, bar_chart, title="Building Inventory Insights")
|
62 |
+
|
63 |
+
# Tabs for Themes
|
64 |
+
tab1, tab2 = st.tabs(["Streamlit Theme", "Altair Native Theme"])
|
65 |
+
|
66 |
+
with tab1:
|
67 |
+
st.altair_chart(chart, theme="streamlit", use_container_width=True)
|
68 |
+
with tab2:
|
69 |
+
st.altair_chart(chart, theme=None, use_container_width=True)
|