Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -75,31 +75,25 @@ def create_range_input(index):
|
|
| 75 |
], className="mb-2")
|
| 76 |
|
| 77 |
@callback(
|
| 78 |
-
Output('ranges-container', 'children'
|
| 79 |
Input('add-range', 'n_clicks'),
|
|
|
|
| 80 |
State('ranges-container', 'children'),
|
| 81 |
prevent_initial_call=True
|
| 82 |
)
|
| 83 |
-
def
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
| 85 |
new_index = len(existing_ranges)
|
| 86 |
new_range = create_range_input(new_index)
|
| 87 |
existing_ranges.append(new_range)
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
|
| 90 |
-
|
| 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'),
|