Nirmal16 commited on
Commit
8ab4e61
·
verified ·
1 Parent(s): 2239362

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -31
app.py CHANGED
@@ -1,33 +1,69 @@
1
  import streamlit as st
 
2
  import pandas as pd
3
- import matplotlib.pyplot as plt
4
-
5
- # Title of the app
6
- st.title("Dataset Visualizer")
7
-
8
- # File uploader for CSV files
9
- url = "https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/building_inventory.csv"
10
-
11
- data = pd.read_csv(url)
12
-
13
- # Display the dataset
14
- st.subheader("Dataset Preview")
15
- st.write(data.head())
16
-
17
- # Display basic statistics
18
- st.subheader("Dataset Summary")
19
- st.write(data.describe())
20
-
21
- # Column selection for visualization
22
- st.subheader("Data Visualization")
23
- column = st.selectbox("Select a column for visualization", data.columns)
24
-
25
- if column:
26
- # Plot histogram for the selected column
27
- st.write(f"Histogram for {column}")
28
- fig, ax = plt.subplots()
29
- data[column].hist(bins=20, ax=ax, color='skyblue', edgecolor='black')
30
- ax.set_title(f"Histogram of {column}")
31
- ax.set_xlabel(column)
32
- ax.set_ylabel("Frequency")
33
- st.pyplot(fig)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)