is445_demo / app.py
mtrzu's picture
Upload app.py
7589a75 verified
import pandas as pd
import streamlit as st
import pandas as pd
import altair as alt
alt.data_transformers.disable_max_rows()
#title
st.title("Illinois Professional Licenses")
st.text("IS445 HW6")
#df
df = pd.read_csv('licenses_fall2022.csv')
df["Original Issue Date"] = pd.to_datetime(df["Original Issue Date"], errors="coerce")
df["Issue Year"] = df["Original Issue Date"].dt.year
df = df.dropna(subset=["Issue Year", "License Type"])
#vis 1
st.header("Visualization 1: License Status by Type")
# Dropdown to select license status
status_choice = st.selectbox(
"Select a License Status:",
sorted(df["License Status"].unique())
)
# Filter by the selected status
filtered = df[df["License Status"] == status_choice]
# Add hover + click interactivity
click1 = alt.selection_point(fields=['License Type'], on='click', empty='all')
hover1 = alt.selection_single(fields=['License Type'], on='mouseover', empty='none')
chart1 = (
alt.Chart(filtered)
.mark_bar()
.encode(
x=alt.X("License Type:N", sort="-y", title="License Type"),
y=alt.Y("count()", title="Number of Licenses"),
color=alt.condition(
hover1 | click1,
alt.Color("License Type:N", legend=None, scale=alt.Scale(scheme="tableau20")),
alt.value("lightgray")
),
tooltip=["License Type", "count()"]
)
.add_params(click1, hover1)
.properties(width=700, height=400,
title=f"Number of {status_choice} Licenses by Type")
)
tab1, tab2 = st.tabs(["Streamlit theme", "Altair native theme"])
with tab1:
st.altair_chart(chart1, theme="streamlit", use_container_width=True)
with tab2:
st.altair_chart(chart1, theme=None, use_container_width=True)
st.write("""
**Description:**
This visualization shows which professional license types are most common for a certain status.
I designed it as a bar chart to compare categories with ease, using a broad color palette to seperate each license type and have strong contrast for people with color blindess and visual contrast needs.
The X displays the different license types, and the Y signifies then number of licenses for easy comparison between licenses.
The dropdown lets users look at the different statuses of the licenses, such as Active, Not Renewed, Cancelled, and more.
If I had more time, I would possibly refine license categories by grouping very similar ones and possibly add filters for years or countries.
""")
#vis2
st.header("Visualization 2: Licenses Issued Over Time")
year_min, year_max = int(df["Issue Year"].min()), int(df["Issue Year"].max())
year_range = st.slider("Select a range of years:", year_min, year_max, (year_min, year_max))
time_filtered = df[(df["Issue Year"] >= year_range[0]) & (df["Issue Year"] <= year_range[1])]
brush = alt.selection_interval(encodings=['x'])
click2 = alt.selection_point(fields=['License Status'], on='click', empty='all')
# Top chart
points = (
alt.Chart(time_filtered)
.mark_line(point=True)
.encode(
x=alt.X("Issue Year:O", title="Year"),
y=alt.Y("count()", title="Number of Licenses Issued"),
color=alt.condition(
click2,
alt.Color("License Status:N", scale=alt.Scale(scheme="spectral")),
alt.value("lightgray")
),
tooltip=["Issue Year", "License Status", "count()"]
)
.properties(width=700, height=300)
.add_params(brush)
)
# Bottom chart:
bars = (
alt.Chart(time_filtered)
.mark_bar()
.encode(
y=alt.Y("License Status:N", sort='-x', title="License Status"),
x=alt.X("count()", title="Number of Licenses"),
color=alt.condition(
click2,
alt.Color("License Status:N", scale=alt.Scale(scheme="spectral")),
alt.value("lightgray")
),
tooltip=["License Status", "count()"]
)
.transform_filter(brush)
.add_params(click2)
)
chart2 = alt.vconcat(points, bars, title="Licenses Issued Over Time by Status")
tab3, tab4 = st.tabs(["Streamlit theme", "Altair native theme"])
with tab3:
st.altair_chart(chart2, theme="streamlit", use_container_width=True)
with tab4:
st.altair_chart(chart2, theme=None, use_container_width=True)
st.write("""
**Description:**
This line chart shows how the number of licenses issued changes over time, grouped by the status of the licenses.
The x coordinate is the years covered in the datset, chronologically ordered, to show the linear change in time and license status. The y coordinate is the number of licenses per license status for that given year.
You can hover over points in the line graph to see the year a little easier. At the top, you can also select a specific range of years you want to look at.
The bar chart displays the count of the license status, and is linked to the bar chart.
The X in the bottom chart shows the number of licenses per the license status, and the Y shows the license status for easier reading and comparison.
I made the colors for both of these charts the same so that they were coordinated, and the broad color palette and contrast was again chosen with accessibility in mind.
If you click a certain status, it will highlight it in both charts so you can easily see, the colors coordinated for ease of understanding.
I think if I had more time, I would add filters for license type or country, and also explore the spike in 1998 for licenses, especially those that were not renewed. Id also play around with the view more, to make it a little easier to see the years.
""")