msa17 commited on
Commit
9de66d5
·
verified ·
1 Parent(s): 99d876c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -61
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
- st.text("The URL for this app is: https://huggingface.co/spaces/msa17/is445_demo")
 
 
 
 
 
 
 
16
 
17
- source = data.seattle_weather()
 
 
 
 
18
 
19
- scale = alt.Scale(
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
- # We create two selections:
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
- # Top panel is scatter plot of temperature vs time
32
- points = (
33
- alt.Chart()
34
- .mark_point()
35
- .encode(
36
- alt.X("monthdate(date):T", title="Date (Month Year)"),
37
- alt.Y(
38
- "temp_max:Q",
39
- title="Maximum Daily Temperature (C)",
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
- # Bottom panel is a bar chart of weather type
51
- bars = (
52
- alt.Chart()
53
- .mark_bar()
54
- .encode(
55
- x="count()",
56
- y="weather:N",
57
- color=alt.condition(click, color, alt.value("lightgray")),
58
- )
59
- .transform_filter(brush)
60
- .properties(
61
- width=550,
62
- )
63
- .add_params(click)
64
- )
65
 
66
- chart = alt.vconcat(points, bars, data=source, title="Seattle Weather - 2009 to 2016")
 
 
 
 
 
 
 
 
 
 
 
67
 
68
- tab1, tab2 = st.tabs(["Streamlit theme (default)", "Altair native theme"])
 
 
 
 
 
 
 
 
 
 
69
 
70
- with tab1:
71
- st.altair_chart(chart, theme="streamlit", use_container_width=True)
72
- with tab2:
73
- st.altair_chart(chart, theme=None, use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
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
+ """)