Spaces:
Running
Running
Jon Solow
commited on
Commit
•
fb558a3
1
Parent(s):
a072434
Add Snap Counts with filters and allow for option in streamlit_filter
Browse files- src/pages/7_Snap_Counts.py +20 -3
- src/streamlit_filter.py +6 -3
src/pages/7_Snap_Counts.py
CHANGED
@@ -17,7 +17,7 @@ def load_data():
|
|
17 |
|
18 |
|
19 |
def get_page():
|
20 |
-
page_title = f"
|
21 |
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
|
22 |
common_page_config()
|
23 |
st.title(page_title)
|
@@ -27,13 +27,30 @@ def get_page():
|
|
27 |
st.write(f"Data loaded as of: {data_load_time_str} UTC")
|
28 |
|
29 |
with st.container():
|
30 |
-
filtered_data = filter_dataframe(data)
|
31 |
st.dataframe(
|
32 |
filtered_data,
|
33 |
hide_index=True,
|
34 |
# height=35 * (len(filtered_data) + 1) + 12,
|
35 |
use_container_width=False,
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
)
|
38 |
|
39 |
|
|
|
17 |
|
18 |
|
19 |
def get_page():
|
20 |
+
page_title = f"Snap Counts and Percentages - {YEAR}"
|
21 |
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
|
22 |
common_page_config()
|
23 |
st.title(page_title)
|
|
|
27 |
st.write(f"Data loaded as of: {data_load_time_str} UTC")
|
28 |
|
29 |
with st.container():
|
30 |
+
filtered_data = filter_dataframe(data, force_on=True, force_on_columns=["team", "position", "week", "opponent"])
|
31 |
st.dataframe(
|
32 |
filtered_data,
|
33 |
hide_index=True,
|
34 |
# height=35 * (len(filtered_data) + 1) + 12,
|
35 |
use_container_width=False,
|
36 |
+
column_order=[
|
37 |
+
"season",
|
38 |
+
"game_type",
|
39 |
+
"week",
|
40 |
+
"player",
|
41 |
+
"position",
|
42 |
+
"team",
|
43 |
+
"opponent",
|
44 |
+
"offense_snaps",
|
45 |
+
"offense_pct",
|
46 |
+
"defense_snaps",
|
47 |
+
"defense_pct",
|
48 |
+
"st_snaps",
|
49 |
+
"st_pct",
|
50 |
+
],
|
51 |
+
column_config={
|
52 |
+
"season": st.column_config.TextColumn(help="Year of NFL Season"),
|
53 |
+
},
|
54 |
)
|
55 |
|
56 |
|
src/streamlit_filter.py
CHANGED
@@ -10,7 +10,7 @@ import pandas as pd
|
|
10 |
import streamlit as st
|
11 |
|
12 |
|
13 |
-
def filter_dataframe(df: pd.DataFrame) -> pd.DataFrame:
|
14 |
"""
|
15 |
Adds a UI on top of a dataframe to let viewers filter columns
|
16 |
|
@@ -20,7 +20,10 @@ def filter_dataframe(df: pd.DataFrame) -> pd.DataFrame:
|
|
20 |
Returns:
|
21 |
pd.DataFrame: Filtered dataframe
|
22 |
"""
|
23 |
-
|
|
|
|
|
|
|
24 |
|
25 |
if not modify:
|
26 |
return df
|
@@ -41,7 +44,7 @@ def filter_dataframe(df: pd.DataFrame) -> pd.DataFrame:
|
|
41 |
modification_container = st.container()
|
42 |
|
43 |
with modification_container:
|
44 |
-
to_filter_columns = st.multiselect("Filter dataframe on", df.columns)
|
45 |
for column in to_filter_columns:
|
46 |
left, right = st.columns((1, 20))
|
47 |
# Treat columns with < 17 unique values as categorical
|
|
|
10 |
import streamlit as st
|
11 |
|
12 |
|
13 |
+
def filter_dataframe(df: pd.DataFrame, force_on: bool = False, force_on_columns: list[str] = []) -> pd.DataFrame:
|
14 |
"""
|
15 |
Adds a UI on top of a dataframe to let viewers filter columns
|
16 |
|
|
|
20 |
Returns:
|
21 |
pd.DataFrame: Filtered dataframe
|
22 |
"""
|
23 |
+
if force_on:
|
24 |
+
modify = True
|
25 |
+
else:
|
26 |
+
modify = st.checkbox("Add more filters")
|
27 |
|
28 |
if not modify:
|
29 |
return df
|
|
|
44 |
modification_container = st.container()
|
45 |
|
46 |
with modification_container:
|
47 |
+
to_filter_columns = st.multiselect("Filter dataframe on", df.columns) + force_on_columns
|
48 |
for column in to_filter_columns:
|
49 |
left, right = st.columns((1, 20))
|
50 |
# Treat columns with < 17 unique values as categorical
|