Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -70,12 +70,16 @@ with button_col3:
|
|
| 70 |
if st.session_state.get('select_columns', False):
|
| 71 |
st.write("Please choose the 'lob' column and the values to filter by:")
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
# Create two columns: one for the 'lob' column dropdown, one for the checkboxes
|
| 74 |
col1, col2 = st.columns(2)
|
| 75 |
|
| 76 |
-
# Dropdown to select the 'lob' column
|
| 77 |
with col1:
|
| 78 |
-
lob_column = st.selectbox('Choose the column for "lob":',
|
| 79 |
|
| 80 |
# Initialize an empty list to hold the selected values
|
| 81 |
selected_lob_values = []
|
|
@@ -83,8 +87,13 @@ if st.session_state.get('select_columns', False):
|
|
| 83 |
# Generate checkboxes for each unique value in the 'lob' column
|
| 84 |
with col2:
|
| 85 |
st.write("Select values for filtering:")
|
|
|
|
| 86 |
if 'lob_column' in st.session_state and st.session_state['lob_column'] in st.session_state['premiums_df'].columns:
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
# Create a checkbox for each unique value in the 'lob' column
|
| 89 |
if st.checkbox(f"{value}", key=f"checkbox_{value}"):
|
| 90 |
selected_lob_values.append(value)
|
|
|
|
| 70 |
if st.session_state.get('select_columns', False):
|
| 71 |
st.write("Please choose the 'lob' column and the values to filter by:")
|
| 72 |
|
| 73 |
+
# Determine columns with only string values
|
| 74 |
+
string_columns = [col for col in st.session_state['premiums_df'].columns
|
| 75 |
+
if st.session_state['premiums_df'][col].dropna().apply(lambda x: isinstance(x, str)).all()]
|
| 76 |
+
|
| 77 |
# Create two columns: one for the 'lob' column dropdown, one for the checkboxes
|
| 78 |
col1, col2 = st.columns(2)
|
| 79 |
|
| 80 |
+
# Dropdown to select the 'lob' column, filtered to only string columns
|
| 81 |
with col1:
|
| 82 |
+
lob_column = st.selectbox('Choose the column for "lob":', string_columns, key='lob_column')
|
| 83 |
|
| 84 |
# Initialize an empty list to hold the selected values
|
| 85 |
selected_lob_values = []
|
|
|
|
| 87 |
# Generate checkboxes for each unique value in the 'lob' column
|
| 88 |
with col2:
|
| 89 |
st.write("Select values for filtering:")
|
| 90 |
+
# Ensure that 'lob_column' is in the session state and it's in the DataFrame columns
|
| 91 |
if 'lob_column' in st.session_state and st.session_state['lob_column'] in st.session_state['premiums_df'].columns:
|
| 92 |
+
# Retrieve unique values from the 'lob' column
|
| 93 |
+
unique_values = st.session_state['premiums_df'][st.session_state['lob_column']].unique()
|
| 94 |
+
# Sort the values for consistent checkbox ordering
|
| 95 |
+
unique_values.sort()
|
| 96 |
+
for value in unique_values:
|
| 97 |
# Create a checkbox for each unique value in the 'lob' column
|
| 98 |
if st.checkbox(f"{value}", key=f"checkbox_{value}"):
|
| 99 |
selected_lob_values.append(value)
|