Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -132,12 +132,12 @@ with col3:
|
|
| 132 |
# # ... include other selections as well
|
| 133 |
# }
|
| 134 |
|
| 135 |
-
|
| 136 |
# Initialize session state variables
|
| 137 |
st.session_state.setdefault('current_page', 'home')
|
| 138 |
st.session_state.setdefault('premiums_df', None)
|
| 139 |
st.session_state.setdefault('claims_recoveries_df', None)
|
| 140 |
st.session_state.setdefault('claims_count_df', None)
|
|
|
|
| 141 |
|
| 142 |
# Helper function to check if a string has more than 50% numeric characters
|
| 143 |
def is_mostly_numeric(s):
|
|
@@ -161,10 +161,18 @@ def column_selection_ui(dataframe_key, selection_key):
|
|
| 161 |
if not any(not isinstance(x, str) or is_mostly_numeric(x) for x in st.session_state[dataframe_key][col].dropna())
|
| 162 |
]
|
| 163 |
|
|
|
|
|
|
|
|
|
|
| 164 |
col1, col2 = st.columns(2)
|
| 165 |
with col1:
|
| 166 |
-
lob_column = st.selectbox(
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
with col2:
|
| 170 |
st.write("Select values for filtering:")
|
|
@@ -172,8 +180,12 @@ def column_selection_ui(dataframe_key, selection_key):
|
|
| 172 |
unique_values = st.session_state[dataframe_key][lob_column].unique()
|
| 173 |
unique_values.sort()
|
| 174 |
for value in unique_values:
|
| 175 |
-
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
# Filter the DataFrame based on selected 'lob' values
|
| 179 |
if selected_lob_values:
|
|
@@ -184,15 +196,14 @@ def column_selection_ui(dataframe_key, selection_key):
|
|
| 184 |
st.write("Now, select the columns for other parameters:")
|
| 185 |
valuation_as_at = st.selectbox('Valuation As At:', filtered_df.columns, key='valuation_as_at_' + selection_key)
|
| 186 |
quarter_bracket = st.selectbox('Quarter Bracket:', filtered_df.columns, key='quarter_bracket_' + selection_key)
|
| 187 |
-
# Continue with other selections as required...
|
| 188 |
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
|
| 197 |
# File uploaders and buttons
|
| 198 |
if st.session_state.current_page == 'home':
|
|
@@ -226,5 +237,10 @@ if st.session_state.current_page.endswith('_selection'):
|
|
| 226 |
# Back to Home button
|
| 227 |
if st.session_state.current_page != 'home':
|
| 228 |
if st.button("Back to Home"):
|
| 229 |
-
st.session_state
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
|
|
|
|
| 132 |
# # ... include other selections as well
|
| 133 |
# }
|
| 134 |
|
|
|
|
| 135 |
# Initialize session state variables
|
| 136 |
st.session_state.setdefault('current_page', 'home')
|
| 137 |
st.session_state.setdefault('premiums_df', None)
|
| 138 |
st.session_state.setdefault('claims_recoveries_df', None)
|
| 139 |
st.session_state.setdefault('claims_count_df', None)
|
| 140 |
+
st.session_state.setdefault('back_to_home', False) # Flag for back to home button
|
| 141 |
|
| 142 |
# Helper function to check if a string has more than 50% numeric characters
|
| 143 |
def is_mostly_numeric(s):
|
|
|
|
| 161 |
if not any(not isinstance(x, str) or is_mostly_numeric(x) for x in st.session_state[dataframe_key][col].dropna())
|
| 162 |
]
|
| 163 |
|
| 164 |
+
# Restore previous selections if they exist
|
| 165 |
+
previous_selections = st.session_state.get(f'{selection_key}_selections', {})
|
| 166 |
+
|
| 167 |
col1, col2 = st.columns(2)
|
| 168 |
with col1:
|
| 169 |
+
lob_column = st.selectbox(
|
| 170 |
+
'Choose the column for "lob":',
|
| 171 |
+
string_columns,
|
| 172 |
+
key=f'lob_column_{selection_key}',
|
| 173 |
+
index=string_columns.index(previous_selections.get('lob_column')) if previous_selections.get('lob_column') in string_columns else 0
|
| 174 |
+
)
|
| 175 |
+
selected_lob_values = previous_selections.get('selected_lob_values', [])
|
| 176 |
|
| 177 |
with col2:
|
| 178 |
st.write("Select values for filtering:")
|
|
|
|
| 180 |
unique_values = st.session_state[dataframe_key][lob_column].unique()
|
| 181 |
unique_values.sort()
|
| 182 |
for value in unique_values:
|
| 183 |
+
is_checked = value in selected_lob_values
|
| 184 |
+
if st.checkbox(f"{value}", key=f"checkbox_{value}_{selection_key}", value=is_checked):
|
| 185 |
+
if not is_checked:
|
| 186 |
+
selected_lob_values.append(value)
|
| 187 |
+
else:
|
| 188 |
+
selected_lob_values.remove(value)
|
| 189 |
|
| 190 |
# Filter the DataFrame based on selected 'lob' values
|
| 191 |
if selected_lob_values:
|
|
|
|
| 196 |
st.write("Now, select the columns for other parameters:")
|
| 197 |
valuation_as_at = st.selectbox('Valuation As At:', filtered_df.columns, key='valuation_as_at_' + selection_key)
|
| 198 |
quarter_bracket = st.selectbox('Quarter Bracket:', filtered_df.columns, key='quarter_bracket_' + selection_key)
|
|
|
|
| 199 |
|
| 200 |
+
# Store the column selections in the session state
|
| 201 |
+
st.session_state[f'{selection_key}_selections'] = {
|
| 202 |
+
'lob_column': lob_column,
|
| 203 |
+
'selected_lob_values': selected_lob_values,
|
| 204 |
+
'valuation_as_at': valuation_as_at,
|
| 205 |
+
'quarter_bracket': quarter_bracket,
|
| 206 |
+
}
|
| 207 |
|
| 208 |
# File uploaders and buttons
|
| 209 |
if st.session_state.current_page == 'home':
|
|
|
|
| 237 |
# Back to Home button
|
| 238 |
if st.session_state.current_page != 'home':
|
| 239 |
if st.button("Back to Home"):
|
| 240 |
+
st.session_state['back_to_home'] = True
|
| 241 |
+
|
| 242 |
+
# Handling the back to home action
|
| 243 |
+
if st.session_state['back_to_home']:
|
| 244 |
+
st.session_state['current_page'] = 'home'
|
| 245 |
+
st.session_state['back_to_home'] = False
|
| 246 |
|