Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,73 +1,56 @@
|
|
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('My First Streamlit App')
|
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 |
-
|
29 |
-
|
|
|
30 |
|
31 |
-
#
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
.
|
36 |
-
|
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 |
-
|
51 |
-
|
52 |
-
|
53 |
-
.
|
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 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
-
|
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 |
+
# Load dataset
|
6 |
+
DATA_URL = "https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/building_inventory.csv"
|
7 |
|
8 |
+
@st.cache
|
9 |
+
def load_data():
|
10 |
+
return pd.read_csv(DATA_URL)
|
11 |
|
12 |
+
df = load_data()
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
# Streamlit app title and description
|
15 |
+
st.title("Building Inventory Visualization")
|
16 |
+
st.markdown("""
|
17 |
+
This app visualizes the building inventory dataset.
|
18 |
+
Use the controls in the sidebar to explore the data.
|
19 |
+
""")
|
20 |
|
21 |
+
# Sidebar for user input
|
22 |
+
st.sidebar.header("Filter Options")
|
23 |
+
state_filter = st.sidebar.multiselect(
|
24 |
+
"Select State(s):",
|
25 |
+
options=df["State"].dropna().unique(),
|
26 |
+
default=df["State"].dropna().unique()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
)
|
28 |
|
29 |
+
agency_filter = st.sidebar.multiselect(
|
30 |
+
"Select Agency(ies):",
|
31 |
+
options=df["Agency Name"].dropna().unique(),
|
32 |
+
default=df["Agency Name"].dropna().unique()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
)
|
34 |
|
35 |
+
# Apply filters to the data
|
36 |
+
filtered_data = df[df["State"].isin(state_filter) & df["Agency Name"].isin(agency_filter)]
|
37 |
+
|
38 |
+
# Display filtered data table
|
39 |
+
st.subheader("Filtered Data Table")
|
40 |
+
st.write(filtered_data)
|
41 |
+
|
42 |
+
# Bar chart of buildings by agency
|
43 |
+
st.subheader("Buildings by Agency")
|
44 |
+
agency_building_counts = filtered_data["Agency Name"].value_counts().reset_index()
|
45 |
+
agency_building_counts.columns = ["Agency Name", "Building Count"]
|
46 |
+
|
47 |
+
chart = alt.Chart(agency_building_counts).mark_bar().encode(
|
48 |
+
x=alt.X("Building Count", title="Number of Buildings"),
|
49 |
+
y=alt.Y("Agency Name", sort="-x", title="Agency Name"),
|
50 |
+
tooltip=["Agency Name", "Building Count"]
|
51 |
+
).properties(
|
52 |
+
width=800,
|
53 |
+
height=400
|
54 |
+
)
|
55 |
|
56 |
+
st.altair_chart(chart, use_container_width=True)
|
|
|
|
|
|