Armeddinosaur commited on
Commit
c52f9e4
·
1 Parent(s): c08520d

Updating task selection to checkbox

Browse files
Files changed (1) hide show
  1. src/components/filters.py +25 -20
src/components/filters.py CHANGED
@@ -24,6 +24,10 @@ def initialize_session_state(df):
24
  # Make sure selected_tasks only includes actual tasks from the dataframe
25
  valid_tasks = [col for col in df.columns if col not in ['Model Type']]
26
  st.session_state.selected_tasks = [task for task in st.session_state.selected_tasks if task in valid_tasks]
 
 
 
 
27
 
28
  # Always select all model types
29
  st.session_state.selected_model_types = list(df['Model Type'].unique())
@@ -73,7 +77,7 @@ def render_metric_selection():
73
 
74
  def render_task_selection(df):
75
  """
76
- Render the task selection component
77
 
78
  Args:
79
  df (pandas.DataFrame): The DataFrame with model data
@@ -86,43 +90,44 @@ def render_task_selection(df):
86
  # Extract task columns (exclude Model Type and Overall)
87
  all_tasks = [col for col in df.columns if col not in ['Model Type']]
88
 
89
- # Determine number of columns based on screen width
90
- num_cols = 3 # Default for medium screens
91
 
92
- # Create task buttons in a fixed number of columns with balanced width
93
  task_groups = [all_tasks[i:i+num_cols] for i in range(0, len(all_tasks), num_cols)]
94
 
95
- # Custom CSS for button styling
 
 
 
 
96
  st.markdown("""
97
  <style>
98
- /* Make buttons same width in their columns and centered */
99
- .stButton > button {
100
- width: 100%;
101
- max-width: 300px;
102
- margin: 0 auto;
103
- display: block;
104
  }
105
  </style>
106
  """, unsafe_allow_html=True)
107
 
108
- # Display buttons in rows
109
  for group in task_groups:
110
  # Create columns with equal width
111
  cols = st.columns(num_cols)
112
 
113
- # Add buttons to each column
114
  for i, task in enumerate(group):
115
  if i < len(cols): # Ensure we don't exceed available columns
116
  with cols[i]:
117
  is_selected = task in st.session_state.selected_tasks
118
- button_label = f"✓ {task}" if is_selected else task
119
- button_type = "primary" if is_selected else "secondary"
120
 
121
- if st.button(button_label, key=f"task_{task}", type=button_type):
122
- if is_selected:
123
- st.session_state.selected_tasks.remove(task)
124
- else:
125
  st.session_state.selected_tasks.append(task)
126
- st.rerun() # Force UI update
 
 
127
 
128
  return st.session_state.selected_tasks
 
24
  # Make sure selected_tasks only includes actual tasks from the dataframe
25
  valid_tasks = [col for col in df.columns if col not in ['Model Type']]
26
  st.session_state.selected_tasks = [task for task in st.session_state.selected_tasks if task in valid_tasks]
27
+
28
+ # If no tasks are selected, select all tasks
29
+ if not st.session_state.selected_tasks:
30
+ st.session_state.selected_tasks = valid_tasks
31
 
32
  # Always select all model types
33
  st.session_state.selected_model_types = list(df['Model Type'].unique())
 
77
 
78
  def render_task_selection(df):
79
  """
80
+ Render the task selection component with checkboxes
81
 
82
  Args:
83
  df (pandas.DataFrame): The DataFrame with model data
 
90
  # Extract task columns (exclude Model Type and Overall)
91
  all_tasks = [col for col in df.columns if col not in ['Model Type']]
92
 
93
+ # Increase number of columns to reduce spacing
94
+ num_cols = 4 # More columns for tighter spacing
95
 
96
+ # Create task groups in a fixed number of columns with balanced width
97
  task_groups = [all_tasks[i:i+num_cols] for i in range(0, len(all_tasks), num_cols)]
98
 
99
+ # Clear selected tasks if it's empty or not initialized
100
+ if 'selected_tasks' not in st.session_state or not st.session_state.selected_tasks:
101
+ st.session_state.selected_tasks = []
102
+
103
+ # Add custom CSS to reduce spacing between checkboxes
104
  st.markdown("""
105
  <style>
106
+ /* Reduce spacing in checkbox containers */
107
+ .stCheckbox {
108
+ padding: 0px !important;
109
+ margin-bottom: 5px !important;
 
 
110
  }
111
  </style>
112
  """, unsafe_allow_html=True)
113
 
114
+ # Display checkboxes in rows
115
  for group in task_groups:
116
  # Create columns with equal width
117
  cols = st.columns(num_cols)
118
 
119
+ # Add checkboxes to each column
120
  for i, task in enumerate(group):
121
  if i < len(cols): # Ensure we don't exceed available columns
122
  with cols[i]:
123
  is_selected = task in st.session_state.selected_tasks
 
 
124
 
125
+ # Use checkbox instead of button
126
+ if st.checkbox(task, value=is_selected, key=f"task_checkbox_{task}"):
127
+ if task not in st.session_state.selected_tasks:
 
128
  st.session_state.selected_tasks.append(task)
129
+ else:
130
+ if task in st.session_state.selected_tasks:
131
+ st.session_state.selected_tasks.remove(task)
132
 
133
  return st.session_state.selected_tasks