Spaces:
Sleeping
Sleeping
dvjgenis commited on
Commit ·
4d0282b
1
Parent(s): 45cf815
Final Project P2 & P3
Browse filesFiles changed (3)
- README.md+21-14
- src/app.pyAdded+192
- src/streamlit_app.pyDeleted-40
1234567891011121314151617181920---title: Is445 Final Projectemoji: 🚀colorFrom: redcolorTo: redsdk: dockerapp_port: 8501tags:- streamlitpinned: falseshort_description: Streamlit template spacelicense: mit---# Welcome to Streamlit!Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [communityforums](https://discuss.streamlit.io).123456789101112131415161718192021222324252627---title: IS 445 Final Project Part 2 Streamlit App - Chicago Public Schools Dashboard (2011 - 2012)emoji: 🏢colorFrom: bluecolorTo: graysdk: streamlitsdk_version: 1.43.2app_file: app.pypinned: falselicense: mitshort_description: Chicago Public Schools Progress Report Cards Dataset------title: IS 445 Final Project Part 3 Streamlit App - Chicago Public Schools Data Journalism (2011 - 2012)emoji: 🏢colorFrom: bluecolorTo: graysdk: streamlitsdk_version: 1.43.2app_file: app.pypinned: falselicense: mitshort_description: Chicago Public Schools Progress Report Cards Dataset---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192# Instructions:# 1. Open a "Terminal" by: View --> Terminal OR just the "Terminal" through the hamburger menu.# 2. Run in terminal with: streamlit run app.py.# 3. Click the "Open in Browser" link which pops up OR click on "Ports" & copy the URL.# 4. Open a Simple Browser with View --> Command Palette --> Simple Browser: Show.# 5. Use the URL from prior steps as input into this simple browser.import altair as altimport pandas as pdimport streamlit as st
# Load the dataset.df = pd.read_csv("https://data.cityofchicago.org/api/views/9xs2-f89t/rows.csv")
# Title & group member names.st.title("Chicago Public Schools Dashboard (2011 - 2012)")st.write("Nicholas Wong, Dulf Genis, Qi Deng, & Shreya Shetty")st.text("Streamlit URL: https://huggingface.co/spaces/TheWongLife/is445_final_project_part_2")
# Clean data for plotting.df_clean = df.dropna(subset = ["Average Student Attendance", "ISAT Exceeding Reading % ", "Safety Score"])
# Dashboard description for non-experts.st.write("""### How to Use This DashboardThis dashboard helps you explore how Chicago public schools performed in the 2011 - 2012 school year. The top chart is a scatter plot where each dot is a school, with its average student attendance on the x-axis & the percentage of students exceeding reading standards on the y-axis — colored dots show if it’s an Elementary (ES), Middle (MS), or High (HS) school. Click on 1 or more dots (Hold Shift to select multiple) to pick schools, & the bottom chart will update to show a bar chart of average safety scores for each school type (Elementary, middle, high) based on your selection. If no schools are selected, it shows the average safety scores for all schools by type. This helps you see how safety varies across school types for schools with different attendance & reading levels.""")
# Driver Plot 1: Attendance vs. Reading Scores.st.subheader("Driver Plot: Attendance vs. Reading Performance")selection = alt.selection_interval(encodings = ["x", "y"])scatter = alt.Chart(df_clean).mark_circle(size = 60).encode( x = alt.X("Average Student Attendance:Q", title = "Average Student Attendance (%)"), y = alt.Y("ISAT Exceeding Reading % :Q", title = "ISAT Reading Exceeding (%)"), tooltip = ["Name of School", "Average Student Attendance", "ISAT Exceeding Reading % "], color = alt.Color("Elementary, Middle, or High School:N", title = "School Type")).properties( width = 600, height = 400).add_params(selection)
st.altair_chart(scatter, use_container_width = True)
# Driven Plot: Average Safety Score by School Type.st.subheader("Driven Plot: Average Safety Score by School Type")bar = alt.Chart(df_clean).mark_bar().encode( x = alt.X("Elementary, Middle, or High School:N", title = "School Type"), y = alt.Y("mean(Safety Score):Q", title = "Average Safety Score"), color = alt.Color("Elementary, Middle, or High School:N", title = "School Type"), tooltip = ["Elementary, Middle, or High School", "mean(Safety Score)"]).transform_filter( selection).properties( width = 600, height = 300).interactive()
# Combine charts to link them.combined_chart = scatter & barst.altair_chart(combined_chart, use_container_width = True)
# Contextual Dataset Information.st.markdown("""### Contextual Dataset1. **Chicago Crime Data (2011)** - **URL:** [https://data.cityofchicago.org/Public-Safety/Crimes-2011/qzdf-xmn8](https://data.cityofchicago.org/Public-Safety/Crimes-2011/qzdf-xmn8) - **Why Useful:** Linking crime data to school locations could show how safety outside schools (e.g., in surrounding neighborhoods) relates to the internal safety scores we’re analyzing. This context might explain variations in attendance or performance tied to community safety.""")
# Data Hosting Plan.st.markdown("""### Data Hosting PlanOur dataset, "Chicago Public Schools - Progress Report Cards (2011 - 2012)", is 348 KB, well below GitHub’s 100 MiB upload limit. Therefore, no special hosting plan is needed beyond loading it directly from the [Chicago Data Portal CSV URL](https://data.cityofchicago.org/api/views/9xs2-f89t/rows.csv), as stated in our Final Project Part 1. This plan remains unchanged.""")
# Instructions:# 1. Open a "Terminal" by: View --> Terminal OR just the "Terminal" through the hamburger menu.# 2. Run in terminal with: streamlit run app.py.# 3. Click the "Open in Browser" link which pops up OR click on "Ports" & copy the URL.# 4. Open a Simple Browser with View --> Command Palette --> Simple Browser: Show.# 5. Use the URL from prior steps as input into this simple browser.import altair as altimport pandas as pdimport streamlit as st
# Load the main dataset.df = pd.read_csv("https://data.cityofchicago.org/api/views/9xs2-f89t/rows.csv")
# Load the contextual crime dataset.df_crime = pd.read_csv("https://data.cityofchicago.org/api/views/qzdf-xmn8/rows.csv")
# Title & group member names.st.title("Are Chicago Schools Safe & Successful? A Look at 2011 - 2012")st.write("Nicholas Wong, Dulf Genis, Qi Deng, & Shreya Shetty")st.text("Streamlit URL: https://huggingface.co/spaces/TheWongLife/is445_final_project_part_3")
# Clean data for plotting.df_clean = df.dropna(subset = ["Average Student Attendance", "ISAT Exceeding Reading % ", "Safety Score"])
# Introduction paragraph.st.write("""### What Makes a School Thrive?Imagine sending your child to a school where they feel safe, show up every day, & excel in reading. In 2011 - 2012, Chicago Public Schools tracked these very things — safety, attendance, & reading performance — for over 500 schools. We explored this data to see how these factors connect. Our interactive chart below lets you explore how attendance & reading success might relate to safety across elementary, middle, & high schools. Click on dots to see specific schools & their details — it’s a window into what was happening in Chicago’s classrooms over a decade ago.""")
# Central Interactive Visualization: Attendance vs. Reading Scores.st.subheader("Explore Attendance & Reading Success")selection = alt.selection_point(fields = ["Name of School"])scatter = alt.Chart(df_clean).mark_circle(size = 100).encode( x = alt.X("Average Student Attendance:Q", title = "Average Student Attendance (%)", scale = alt.Scale(domain = [50, 100])), y = alt.Y("ISAT Exceeding Reading % :Q", title = "Students Exceeding Reading Standards (%)", scale = alt.Scale(domain = [0, 100])), tooltip = ["Name of School", "Average Student Attendance", "ISAT Exceeding Reading % ", "Safety Score"], color = alt.Color("Elementary, Middle, or High School:N", title = "School Type", scale = alt.Scale(scheme = "category10")), opacity = alt.condition(selection, alt.value(1), alt.value(0.3))).properties( width = 700, height = 500).add_params(selection).interactive()
st.altair_chart(scatter, use_container_width = True)st.caption("Click on dots (Hold Shift for multiple) to see school details. Colors show school types: Elementary (ES), Middle (MS), High (HS).")
# 2nd paragraph: Explaining the central visualization.st.write("""### Safety’s Role in LearningThe chart above shows each school as a dot. Schools with higher attendance (Further right) often have more students exceeding reading standards (Higher up), especially elementary schools (Blue dots). But what about safety? When you click on a dot, you’ll see a safety score from 1 to 99, based on things like discipline incidents & student surveys. We found high schools (Red dots) tend to cluster lower on both attendance & reading, hinting safety might play a role. To further explore, we paired this with crime data from Chicago’s neighborhoods & statewide school trends — check out the visuals below to see the bigger picture.""")
# Contextual Visualization 1: Self-generated bar chart of average safety scores.st.subheader("How Safe Are Chicago Schools by Type?")bar = alt.Chart(df_clean).mark_bar().encode( x = alt.X("Elementary, Middle, or High School:N", title = "School Type"), y = alt.Y("mean(Safety Score):Q", title = "Average Safety Score (1 - 99)", scale = alt.Scale(domain = [0, 100])), color = alt.Color("Elementary, Middle, or High School:N", title = "School Type", scale = alt.Scale(scheme = "category10")), tooltip = ["Elementary, Middle, or High School", "mean(Safety Score)"]).properties( width = 500, height = 300)
st.altair_chart(bar, use_container_width = True)st.caption("Average safety scores for Chicago schools by type, calculated from our primary dataset.")
# Contextual Visualization 2: Self-generated bar chart of top crime types.st.subheader("Top Crimes in Chicago in 2011")crime_counts = df_crime["Primary Type"].value_counts().head().reset_index()crime_counts.columns = ["Crime Type", "Count"]bar_crime = alt.Chart(crime_counts).mark_bar().encode( x = alt.X("Crime Type:N", title = "Crime Type", sort = "-y"), y = alt.Y("Count:Q", title = "Number of Incidents"), color = alt.Color("Crime Type:N", scale = alt.Scale(scheme = "category20"), legend = None), tooltip = ["Crime Type", "Count"]).properties( width = 500, height = 300)
st.altair_chart(bar_crime, use_container_width = True)st.caption("Top 5 crime types reported in Chicago in 2011, based on Chicago Crime Data.")
# 3rd paragraph: Connecting the visualizations.st.write("""### Putting It All TogetherChicago’s schools don’t exist in a bubble — neighborhood safety matters too. Our 1st bar chart shows elementary schools scored highest on safety (Around 50 out of 99), while high schools lagged (Closer to 40). The 2nd chart reveals theft & battery topped Chicago’s crime list in 2011, suggesting challenges near some schools, especially high schools with lower attendance & reading scores. National data from the U.S. Department of Education shows school safety — like fights or theft — is a widespread issue, & Illinois data hints Chicago’s struggles were typical for urban areas. Together, these clues suggest improving safety, both inside schools & out, could improve attendance & learning. What do you think — how should Chicago tackle this today?""")
# Citations.st.markdown("""### Where We Got Our Data- **Primary Dataset:** Chicago Public Schools - Progress Report Cards (2011 - 2012). Available at [https://data.cityofchicago.org/api/views/9xs2-f89t/rows.csv](https://data.cityofchicago.org/api/views/9xs2-f89t/rows.csv). - **Contextual Dataset Source:** Chicago Crime Data (2011). Download from [https://data.cityofchicago.org/api/views/qzdf-xmn8/rows.csv](https://data.cityofchicago.org/api/views/qzdf-xmn8/rows.csv).- **Contextual Dataset Source 2:** National school safety trends referenced from NCES Condition of Education, 'School Crime and Safety' indicator, at [https://nces.ed.gov/programs/coe/indicator/cgb](https://nces.ed.gov/programs/coe/indicator/cgb).""")12345678910111213141516171819202122232425262728293031323334353637383940import altair as altimport numpy as npimport pandas as pdimport streamlit as st
"""# Welcome to Streamlit!
Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [communityforums](https://discuss.streamlit.io).
In the meantime, below is an example of what you can do with just a few lines of code:"""
num_points = st.slider("Number of points in spiral", 1, 10000, 1100)num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
indices = np.linspace(0, 1, num_points)theta = 2 * np.pi * num_turns * indicesradius = indices
x = radius * np.cos(theta)y = radius * np.sin(theta)
df = pd.DataFrame({ "x": x, "y": y, "idx": indices, "rand": np.random.randn(num_points),})
st.altair_chart(alt.Chart(df, height=700, width=700) .mark_point(filled=True) .encode( x=alt.X("x", axis=None), y=alt.Y("y", axis=None), color=alt.Color("idx", legend=None, scale=alt.Scale()), size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])), ))README.md+21-14
src/app.pyAdded+192
src/streamlit_app.pyDeleted-40