diff --git a/ui_programm_fragmente/input_to_checklist.py b/ui_programm_fragmente/input_to_checklist.py index 740b51ed9aad7973cf76b8bd42978dc8e0c1abed..0a9fd94f0d21f31a5c231b3586283e9a3963fd34 100644 --- a/ui_programm_fragmente/input_to_checklist.py +++ b/ui_programm_fragmente/input_to_checklist.py @@ -4,11 +4,11 @@ from dash import html from dash import callback_context from dash.dependencies import Input, Output, State from dash.exceptions import PreventUpdate -import plotly.express as px app = dash.Dash(__name__) list_of_inputs = dict() +additional_options = ['Update Automatically'] app.layout = html.Div([ # Layer 0: For the Header and Help Function(s) @@ -31,6 +31,12 @@ app.layout = html.Div([ html.Button(id='start-button',children='Generate Graph') ]), # Layer 3: For additional Options (e.g. Topological Sort) + html.Div([ + html.H4('Additional Options'), + dcc.Checklist(id='additional-options', + options=[{'label':k,'value':k} for k in additional_options], + value=[]) + ]), # Layer 4: For the Graph html.Div([ html.Div(id='test-output') @@ -50,7 +56,7 @@ input-string is required as Output to clear the input box after each input Input('clear-selected-button','n_clicks'), State('input-checklist','value') ) -def update_input_list(input_value,btn1,btn2,all_values): +def update_input_checklist(input_value,btn1,btn2,all_values): ''' :param input_value: given by dcc.Input :type input_value: string @@ -71,6 +77,7 @@ def update_input_list(input_value,btn1,btn2,all_values): return [{'label': i, 'value': i} for i in list_of_inputs],list(),'' # when the programm is first started: if input_value == '': + list_of_inputs.clear() return list(),list(),'' # when a new element is added via dcc.Input if input_value not in list_of_inputs: @@ -96,36 +103,44 @@ Basic structure for a callback that generates an output @app.callback( Output('test-output','children'), Input('start-button','n_clicks'), - State('input-checklist','options'), - State('input-checklist','value'), - State('forward-depth','value'), - State('backward-depth','value'), + Input('input-checklist','options'), + Input('input-checklist','value'), + Input('forward-depth','value'), + Input('backward-depth','value'), + State('additional-options','value') ) -def generate_output(n_clicks,all_options,all_values,forward_depth,backward_depth): +def generate_output(n_clicks,all_inputs,selected_inputs, + forward_depth,backward_depth,additional_options): ''' :param n_clicks: how often has Generate Graph been clicked :type n_clicks: int - :param all_options: all labels and values from the checklist, + :param all_inputs: all labels and values from the checklist, regardless if they have been checked or not - :type all_options: list of dictionaries with 2 entries each - :param all_values: values of all checked elements - :type all_values: list of strings + :type all_inputs: list of dictionaries with 2 entries each + :param selected_inputs: values of all checked elements + :type selected_inputs: list of strings :param forward_depth: forward recursion depth :type forward_depth: unsigned int :param backward_depth: backward recursion depth :type backward_depth: unsigned int + :param additional_options: value of all selected additional options + :type additional_options: list of strings ''' + changed_id = [p['prop_id'] for p in callback_context.triggered][0] if n_clicks is None: raise PreventUpdate - else: + elif 'Update Automatically' in additional_options \ + or 'start-button' in changed_id: s = '' - for i in range(len(all_options)): - x = all_options[i]['value'] - if x in all_values: + for i in range(len(all_inputs)): + x = all_inputs[i]['value'] + if x in selected_inputs: s += x*(abs(int(forward_depth)-int(backward_depth))) else: s += x*(int(forward_depth)+int(backward_depth)) return s + else: + raise PreventUpdate if __name__ == '__main__': app.run_server(debug=True)