EasySci commited on
Commit
bb4e6a7
·
1 Parent(s): 9d3d386

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -24,7 +24,7 @@ entered_options = ["option1", "option2", "option3", "option5", "option6", "optio
24
  header_buttons = pn.Row(sizing_mode='stretch_width', css_classes=['header-buttons'])
25
 
26
  # "+" button to trigger the addition to the header
27
- add_to_header_button = pn.widgets.Button(name="",icon='search', icon_size='1.5em', button_type='default', styles={'background': '#f0f0f0'})
28
 
29
  # List to store the names of buttons to be added to the header
30
  buttons_to_add = []
@@ -33,8 +33,11 @@ buttons_to_add = []
33
  def add_to_header(event):
34
  selected_options = filter_list.value
35
  if selected_options:
36
- buttons_to_add.extend(selected_options) # Extend the list with selected options
37
- filter_list.value = [] # Clear the selected options after adding them to the list
 
 
 
38
  update_header() # Update the header after adding options
39
 
40
  add_to_header_button.on_click(add_to_header)
@@ -47,9 +50,6 @@ def update_header():
47
  header_button.on_click(remove_from_header) # Add callback to remove the header button
48
  header_buttons.append(header_button)
49
 
50
- # Update the filter list options to exclude buttons that are already in the header
51
- filter_list.options = [option for option in entered_options if option not in buttons_to_add]
52
-
53
  # MultiChoice widget to display the filter options with delete buttons
54
  filter_list = pn.widgets.MultiChoice(
55
  name='',
@@ -65,6 +65,7 @@ filter_list = pn.widgets.MultiChoice(
65
  def remove_from_header(event):
66
  button_name = event.name
67
  buttons_to_add.remove(button_name) # Remove from the header buttons list
 
68
  update_header() # Update the header and filter list
69
 
70
  # Layout using Template
 
24
  header_buttons = pn.Row(sizing_mode='stretch_width', css_classes=['header-buttons'])
25
 
26
  # "+" button to trigger the addition to the header
27
+ add_to_header_button = pn.widgets.Button(name="", icon='search', icon_size='1.5em', button_type='default', styles={'background': '#f0f0f0'})
28
 
29
  # List to store the names of buttons to be added to the header
30
  buttons_to_add = []
 
33
  def add_to_header(event):
34
  selected_options = filter_list.value
35
  if selected_options:
36
+ for option in selected_options:
37
+ if option not in buttons_to_add: # Check if option is already in header
38
+ buttons_to_add.append(option) # Add to header if not already present
39
+ filter_list.options.remove(option) # Remove from filter list options
40
+ filter_list.value = [] # Clear the selected options after adding them to the header
41
  update_header() # Update the header after adding options
42
 
43
  add_to_header_button.on_click(add_to_header)
 
50
  header_button.on_click(remove_from_header) # Add callback to remove the header button
51
  header_buttons.append(header_button)
52
 
 
 
 
53
  # MultiChoice widget to display the filter options with delete buttons
54
  filter_list = pn.widgets.MultiChoice(
55
  name='',
 
65
  def remove_from_header(event):
66
  button_name = event.name
67
  buttons_to_add.remove(button_name) # Remove from the header buttons list
68
+ filter_list.options.append(button_name) # Add back to the filter list options
69
  update_header() # Update the header and filter list
70
 
71
  # Layout using Template