Nirmal16 commited on
Commit
2239362
·
verified ·
1 Parent(s): 82504bd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -69
app.py CHANGED
@@ -1,71 +1,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
- # Add color scale for 'Bldg Status'
22
- building_status_scale = alt.Scale(
23
- domain=["Active", "Inactive", "Unknown"],
24
- range=["#1f77b4", "#ff7f0e", "#d62728"]
25
- )
26
- color = alt.Color("Bldg Status:N", scale=building_status_scale)
27
-
28
- # Selections
29
- brush = alt.selection_interval(encodings=["x"])
30
- click = alt.selection_point(encodings=["color"])
31
-
32
- # Top Panel: Scatter Plot (Year Constructed vs Square Footage)
33
- scatter = (
34
- alt.Chart(data)
35
- .mark_point()
36
- .encode(
37
- alt.X("Year Constructed:Q", title="Year Constructed"),
38
- alt.Y("Square Footage:Q", title="Square Footage"),
39
- color=alt.condition(brush, color, alt.value("lightgray")),
40
- size=alt.Size("Total Floors:Q", scale=alt.Scale(range=[50, 300]), title="Total Floors"),
41
- tooltip=["Agency Name", "Location Name", "Square Footage", "Year Constructed"]
42
- )
43
- .properties(width=550, height=300, title="Building Size by Construction Year")
44
- .add_params(brush)
45
- .transform_filter(click)
46
- )
47
-
48
- # Bottom Panel: Bar Chart (Count of Building Status)
49
- bar_chart = (
50
- alt.Chart(data)
51
- .mark_bar()
52
- .encode(
53
- x="count()",
54
- y=alt.Y("Bldg Status:N", title="Building Status"),
55
- color=alt.condition(click, color, alt.value("lightgray")),
56
- )
57
- .transform_filter(brush)
58
- .properties(width=550, title="Building Status Distribution")
59
- .add_params(click)
60
- )
61
-
62
- # Combined Chart
63
- chart = alt.vconcat(scatter, bar_chart, title="Building Inventory Insights")
64
-
65
- # Tabs for Themes
66
- tab1, tab2 = st.tabs(["Streamlit Theme", "Altair Native Theme"])
67
-
68
- with tab1:
69
- st.altair_chart(chart, theme="streamlit", use_container_width=True)
70
- with tab2:
71
- st.altair_chart(chart, theme=None, use_container_width=True)
 
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)