Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,73 +1,80 @@
|
|
1 |
-
# INSTRUCTIONS:
|
2 |
-
# 1. Open a "Terminal" by: View --> Terminal OR just the "Terminal" through the hamburger menu
|
3 |
-
# 2. run in terminal with: streamlit run app.py
|
4 |
-
# 3. click the "Open in Browser" link that pops up OR click on "Ports" and copy the URL
|
5 |
-
# 4. Open a Simple Browswer with View --> Command Palette --> Simple Browser: Show
|
6 |
-
# 5. use the URL from prior steps as intput into this simple browser
|
7 |
-
|
8 |
-
|
9 |
import streamlit as st
|
|
|
10 |
import altair as alt
|
11 |
-
from vega_datasets import data
|
12 |
-
|
13 |
-
st.title('Streamlit App for IS445: ID16589')
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
domain=["sun", "fog", "drizzle", "rain", "snow"],
|
21 |
-
range=["#e7ba52", "#a7a7a7", "#aec7e8", "#1f77b4", "#9467bd"],
|
22 |
-
)
|
23 |
-
color = alt.Color("weather:N", scale=scale)
|
24 |
|
25 |
-
#
|
26 |
-
|
27 |
-
|
28 |
-
brush = alt.selection_interval(encodings=["x"])
|
29 |
-
click = alt.selection_point(encodings=["color"])
|
30 |
|
31 |
-
#
|
32 |
-
|
33 |
-
|
34 |
-
.
|
35 |
-
.
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
scale=alt.Scale(domain=[-5, 40]),
|
41 |
-
),
|
42 |
-
color=alt.condition(brush, color, alt.value("lightgray")),
|
43 |
-
size=alt.Size("precipitation:Q", scale=alt.Scale(range=[5, 200])),
|
44 |
-
)
|
45 |
-
.properties(width=550, height=300)
|
46 |
-
.add_params(brush)
|
47 |
-
.transform_filter(click)
|
48 |
)
|
|
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
width=550,
|
62 |
-
)
|
63 |
-
.add_params(click)
|
64 |
-
)
|
65 |
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
import altair as alt
|
|
|
|
|
|
|
4 |
|
5 |
+
# Title and Introduction
|
6 |
+
st.title("Building Inventory Visualization")
|
7 |
+
st.markdown("""
|
8 |
+
This app visualizes building inventory data. We explore two key visualizations:
|
9 |
+
1. The distribution of buildings based on their acquisition year.
|
10 |
+
2. A comparison of the square footage for buildings across different usage descriptions.
|
11 |
+
Below, we also provide explanations for each visualization, including design choices and potential improvements.
|
12 |
+
""")
|
13 |
|
14 |
+
# Load Dataset
|
15 |
+
@st.cache
|
16 |
+
def load_data():
|
17 |
+
url = "https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/building_inventory.csv"
|
18 |
+
return pd.read_csv(url)
|
19 |
|
20 |
+
data = load_data()
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
# Data Preprocessing
|
23 |
+
data['Year Acquired'] = pd.to_numeric(data['Year Acquired'], errors='coerce')
|
24 |
+
data['Square Footage'] = pd.to_numeric(data['Square Footage'], errors='coerce')
|
|
|
|
|
25 |
|
26 |
+
# Visualization 1: Distribution of Buildings by Year Acquired
|
27 |
+
st.header("Distribution of Buildings by Year Acquired")
|
28 |
+
year_acquired_chart = alt.Chart(data).mark_bar(color='steelblue').encode(
|
29 |
+
alt.X('Year Acquired:Q', bin=alt.Bin(maxbins=20), title="Year Acquired"),
|
30 |
+
alt.Y('count():Q', title="Number of Buildings")
|
31 |
+
).properties(
|
32 |
+
width=700,
|
33 |
+
height=400,
|
34 |
+
title="Distribution of Buildings by Year Acquired"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
)
|
36 |
+
st.altair_chart(year_acquired_chart, use_container_width=True)
|
37 |
|
38 |
+
st.markdown("""
|
39 |
+
### Explanation
|
40 |
+
This visualization highlights the distribution of buildings based on the year they were acquired.
|
41 |
+
- **Design Choices**:
|
42 |
+
- A bar chart was chosen for clarity, with years grouped into bins for better aggregation.
|
43 |
+
- The steel blue color provides a neutral tone and avoids distraction.
|
44 |
+
- Axis labels and titles were carefully chosen for readability.
|
45 |
+
- **Potential Improvements**:
|
46 |
+
- If more time was available, I would add an interactive filter to explore specific years.
|
47 |
+
- It would also be useful to compare acquisition trends by agency or location.
|
48 |
+
""")
|
|
|
|
|
|
|
|
|
49 |
|
50 |
+
# Visualization 2: Square Footage by Usage Description
|
51 |
+
st.header("Square Footage by Usage Description")
|
52 |
+
usage_chart = alt.Chart(data).mark_boxplot().encode(
|
53 |
+
alt.X('Usage Description:N', title="Usage Description"),
|
54 |
+
alt.Y('Square Footage:Q', title="Square Footage"),
|
55 |
+
color='Usage Description:N'
|
56 |
+
).properties(
|
57 |
+
width=700,
|
58 |
+
height=400,
|
59 |
+
title="Square Footage by Usage Description"
|
60 |
+
)
|
61 |
+
st.altair_chart(usage_chart, use_container_width=True)
|
62 |
|
63 |
+
st.markdown("""
|
64 |
+
### Explanation
|
65 |
+
This visualization compares the square footage of buildings across various usage descriptions.
|
66 |
+
- **Design Choices**:
|
67 |
+
- A boxplot was selected to highlight the distribution of square footage within each usage category.
|
68 |
+
- Colors were added to distinguish categories visually.
|
69 |
+
- The plot was scaled to ensure data clarity and eliminate crowding.
|
70 |
+
- **Potential Improvements**:
|
71 |
+
- Adding a tooltip to show specific statistics (e.g., median, quartiles) for each category.
|
72 |
+
- Including an interactive filter to explore categories of interest.
|
73 |
+
""")
|
74 |
|
75 |
+
# Footer
|
76 |
+
st.markdown("""
|
77 |
+
---
|
78 |
+
**Data Source**: [Building Inventory Dataset](https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/building_inventory.csv)
|
79 |
+
**Author**: Your Name
|
80 |
+
""")
|