ShadisClassExample_inclass / pages /2_Widget_Exploration.py
hyoo14
test
7d76581
raw
history blame contribute delete
811 Bytes
import streamlit as st
st.set_page_config(page_title="Widget Exploration", page_icon=":1234:")
st.sidebar.header("Widget Exploration")
st.title("interactive Plot")
mobility_url = "https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/mobility.csv"
import pandas as pd
df = pd.read_csv(mobility_url)
# st.write(df)
import matplotlib.pyplot as plt
states_selected = st.multiselect("Which states?",
df["State"].unique())
if len(states_selected) > 0:
df_subset = df[df['State'].isin(states_selected)]
fig, ax = plt.subplots()
df_subset.groupby("State")["Mobility"].mean().plot(kind='bar',ax=ax)
st.pyplot(fig)
else:
fig, ax = plt.subplots()
df.groupby("State")["Mobility"].mean().plot(kind='bar',ax=ax)
st.pyplot(fig)