EasySci commited on
Commit
e843d90
·
1 Parent(s): c39f2f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -33,9 +33,6 @@ filter_list = pn.widgets.MultiChoice(
33
  # Create buttons for the header
34
  header_buttons = pn.Column(sizing_mode='stretch_width', css_classes=['header-buttons'])
35
 
36
- # List to store the names of buttons to be added to the header
37
- buttons_to_add = []
38
-
39
  # "+" button to trigger the addition to the header
40
  add_to_header_button = pn.widgets.Button(name="Add to Header", button_type='primary')
41
 
@@ -43,11 +40,25 @@ add_to_header_button = pn.widgets.Button(name="Add to Header", button_type='prim
43
  def add_to_header(event):
44
  selected_option = filter_list.value
45
  if selected_option:
46
- buttons_to_add.append(selected_option[0]) # Store the name of the button to be added
 
47
  filter_list.value = [] # Clear the selected option after adding it to the header
48
 
 
 
 
49
  add_to_header_button.on_click(add_to_header)
50
 
 
 
 
 
 
 
 
 
 
 
51
  # Layout using Template
52
  template = pn.template.FastListTemplate(
53
  title="EasySciRead",
@@ -64,12 +75,5 @@ template = pn.template.FastListTemplate(
64
  sidebar_width=150
65
  )
66
 
67
- # Periodically update the header layout to add the newly created buttons
68
- def update_header():
69
- for button_name in buttons_to_add:
70
- new_button = pn.widgets.Button(name=button_name, width=130, sizing_mode='fixed')
71
- header_buttons.append(new_button)
72
- buttons_to_add.clear() # Clear the list after adding the buttons to the header
73
-
74
  # Run the app
75
  template.servable()
 
33
  # Create buttons for the header
34
  header_buttons = pn.Column(sizing_mode='stretch_width', css_classes=['header-buttons'])
35
 
 
 
 
36
  # "+" button to trigger the addition to the header
37
  add_to_header_button = pn.widgets.Button(name="Add to Header", button_type='primary')
38
 
 
40
  def add_to_header(event):
41
  selected_option = filter_list.value
42
  if selected_option:
43
+ new_button = pn.widgets.Button(name=selected_option[0], width=130, sizing_mode='fixed')
44
+ header_buttons.append(new_button)
45
  filter_list.value = [] # Clear the selected option after adding it to the header
46
 
47
+ # Update the header immediately after adding the button
48
+ update_header()
49
+
50
  add_to_header_button.on_click(add_to_header)
51
 
52
+ # Function to update the header layout with the newly created buttons
53
+ def update_header():
54
+ header_buttons.clear() # Clear the existing buttons
55
+ for button_name in buttons_to_add:
56
+ new_button = pn.widgets.Button(name=button_name, width=130, sizing_mode='fixed')
57
+ header_buttons.append(new_button)
58
+
59
+ # List to store the names of buttons to be added to the header
60
+ buttons_to_add = []
61
+
62
  # Layout using Template
63
  template = pn.template.FastListTemplate(
64
  title="EasySciRead",
 
75
  sidebar_width=150
76
  )
77
 
 
 
 
 
 
 
 
78
  # Run the app
79
  template.servable()