bluenevus commited on
Commit
aed9663
·
verified ·
1 Parent(s): 9be275e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -17
app.py CHANGED
@@ -75,31 +75,25 @@ def create_range_input(index):
75
  ], className="mb-2")
76
 
77
  @callback(
78
- Output('ranges-container', 'children', allow_duplicate=True),
79
  Input('add-range', 'n_clicks'),
 
80
  State('ranges-container', 'children'),
81
  prevent_initial_call=True
82
  )
83
- def add_range(n_clicks, existing_ranges):
84
- if n_clicks:
 
 
 
85
  new_index = len(existing_ranges)
86
  new_range = create_range_input(new_index)
87
  existing_ranges.append(new_range)
88
- return existing_ranges
 
 
89
 
90
- @callback(
91
- Output('ranges-container', 'children', allow_duplicate=True),
92
- Input({'type': 'remove-range', 'index': ALL}, 'n_clicks'),
93
- State('ranges-container', 'children'),
94
- prevent_initial_call=True
95
- )
96
- def remove_range(n_clicks, existing_ranges):
97
- ctx = dash.callback_context
98
- if not ctx.triggered:
99
- raise PreventUpdate
100
- button_id = ctx.triggered[0]['prop_id'].split('.')[0]
101
- index_to_remove = json.loads(button_id)['index']
102
- return [range for i, range in enumerate(existing_ranges) if i != index_to_remove]
103
 
104
  @callback(
105
  Output('progress-bar', 'value'),
 
75
  ], className="mb-2")
76
 
77
  @callback(
78
+ Output('ranges-container', 'children'),
79
  Input('add-range', 'n_clicks'),
80
+ Input({'type': 'remove-range', 'index': ALL}, 'n_clicks'),
81
  State('ranges-container', 'children'),
82
  prevent_initial_call=True
83
  )
84
+ def manage_ranges(add_clicks, remove_clicks, existing_ranges):
85
+ ctx = dash.callback_context
86
+ triggered_id = ctx.triggered[0]['prop_id'].split('.')[0]
87
+
88
+ if triggered_id == 'add-range':
89
  new_index = len(existing_ranges)
90
  new_range = create_range_input(new_index)
91
  existing_ranges.append(new_range)
92
+ elif 'remove-range' in triggered_id:
93
+ remove_index = json.loads(triggered_id)['index']
94
+ existing_ranges = [range for i, range in enumerate(existing_ranges) if i != remove_index]
95
 
96
+ return existing_ranges
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  @callback(
99
  Output('progress-bar', 'value'),