Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +65 -59
- requirements.txt +1 -2
app.py
CHANGED
@@ -1,73 +1,79 @@
|
|
1 |
-
#
|
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 |
-
|
12 |
-
|
13 |
-
st.title('Streamlit App for IS445: ID13029')
|
14 |
|
15 |
-
|
|
|
|
|
16 |
|
17 |
-
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
)
|
23 |
-
color = alt.Color("weather:N", scale=scale)
|
24 |
|
25 |
-
|
26 |
-
# - a brush that is active on the top panel
|
27 |
-
# - a multi-click that is active on the bottom panel
|
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 |
-
|
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 |
-
|
62 |
-
|
63 |
-
|
|
|
64 |
)
|
65 |
|
66 |
-
|
|
|
|
|
67 |
|
68 |
-
tab1, tab2 = st.tabs(["Streamlit theme (default)", "Altair native theme"])
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# put streamlit code here as needed
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
import pandas as pd
|
|
|
4 |
import altair as alt
|
5 |
+
import streamlit as st
|
|
|
|
|
6 |
|
7 |
+
url = "https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/building_inventory.csv"
|
8 |
+
data = pd.read_csv(url)
|
9 |
+
# print(data.head())
|
10 |
|
11 |
+
st.title("Building Inventory Visualization")
|
12 |
+
st.markdown("Displayed here are the data visuals from Building Inventory dataset.")
|
13 |
+
st.write(data.head())
|
14 |
|
15 |
+
# Visualization 1: Buildings by Usage Description
|
16 |
+
st.subheader("Buildings by Usage Description")
|
17 |
+
usage_data = data['Usage Description'].value_counts().reset_index()
|
18 |
+
usage_data.columns = ['Usage Description', 'Count']
|
19 |
+
|
20 |
+
chart5 = alt.Chart(usage_data).mark_bar().encode(
|
21 |
+
x=alt.X('Count:Q', title='Number of Buildings'),
|
22 |
+
y=alt.Y('Usage Description:N', sort='-x', title='Usage Description'),
|
23 |
+
color=alt.Color('Usage Description:N', legend=None),
|
24 |
+
tooltip=['Usage Description', 'Count']
|
25 |
+
).properties(
|
26 |
+
width=600,
|
27 |
+
height=400,
|
28 |
+
title="Buildings by Usage Description"
|
29 |
)
|
|
|
30 |
|
31 |
+
st.altair_chart(chart5, use_container_width=True)
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
# Write-up for Visualization 1
|
34 |
+
st.write("Buildings by Usage Description")
|
35 |
+
st.write(
|
36 |
+
"This bar chart represents the distribution of buildings based on their usage descriptions. "
|
37 |
+
"The x-axis displays the number of buildings, while the y-axis lists the various usage categories. "
|
38 |
+
"Each bar reflects the count of buildings in a specific usage type, with distinct colors to enhance readability and tooltips to show precise values."
|
39 |
+
)
|
40 |
+
st.write(
|
41 |
+
"I chose a bar chart because it effectively highlights the differences in building usage, making comparisons straightforward. "
|
42 |
+
"This visualization allows users to quickly identify the most common and least common usage types. "
|
43 |
+
"If I had more time, I would add advanced interactivity, such as a dropdown menu or filter, to explore specific usage categories or group similar types for deeper insights."
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
)
|
45 |
|
46 |
+
|
47 |
+
# Visualization 2: Floor Count Distribution
|
48 |
+
st.subheader("Distribution of Number of Floors")
|
49 |
+
floor_count_data = data['Total Floors'].dropna().value_counts().reset_index()
|
50 |
+
floor_count_data.columns = ['Total Floors', 'Count']
|
51 |
+
|
52 |
+
chart4 = alt.Chart(floor_count_data).mark_bar().encode(
|
53 |
+
x=alt.X('Total Floors:O', title='Number of Floors'),
|
54 |
+
y=alt.Y('Count:Q', title='Number of Buildings'),
|
55 |
+
color=alt.Color('Total Floors:O', legend=None),
|
56 |
+
tooltip=['Total Floors', 'Count']
|
57 |
+
).properties(
|
58 |
+
width=600,
|
59 |
+
height=400,
|
60 |
+
title="Distribution of Number of Floors in Buildings"
|
61 |
)
|
62 |
|
63 |
+
st.altair_chart(chart4, use_container_width=True)
|
64 |
+
|
65 |
+
|
66 |
|
|
|
67 |
|
68 |
+
# Write-up for Visualization 2
|
69 |
+
st.write("Distribution of Number of Floors")
|
70 |
+
st.write(
|
71 |
+
"This bar chart visualizes the distribution of buildings based on the number of floors. "
|
72 |
+
"The x-axis represents the total number of floors, while the y-axis displays the count of buildings with that floor count. "
|
73 |
+
"Each bar is color-coded to improve visual appeal, and tooltips provide exact counts for added interactivity."
|
74 |
+
)
|
75 |
+
st.write(
|
76 |
+
"I chose a bar chart for this visualization because it effectively captures the distribution of floor counts and allows users to identify trends, "
|
77 |
+
"such as the most common floor counts. This visualization makes it easy to compare the data and spot unusual patterns. "
|
78 |
+
"If I had more time, I would incorporate filters or sliders to let users explore specific floor ranges or analyze the data further by other building attributes such as usage type or region."
|
79 |
+
)
|
requirements.txt
CHANGED
@@ -1,3 +1,2 @@
|
|
1 |
-
|
2 |
altair
|
3 |
-
vega_datasets
|
|
|
1 |
+
pandas
|
2 |
altair
|
|