File size: 811 Bytes
4096d6d
 
 
 
 
7d76581
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)