Skip to content
Snippets Groups Projects
Commit 3c5d495f authored by David, Sebastian's avatar David, Sebastian
Browse files

Fixed a major bug,

where users would see the changes that other users
make, by removing dependency on a global variable.
changed some more variable names and updated code documentation.
parent 5a78e24d
No related branches found
No related tags found
1 merge request!8UI Hinzufügen
...@@ -4,10 +4,10 @@ from dash import html ...@@ -4,10 +4,10 @@ from dash import html
from dash import callback_context from dash import callback_context
from dash.dependencies import Input, Output, State from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate from dash.exceptions import PreventUpdate
import copy
app = dash.Dash(__name__) app = dash.Dash(__name__)
list_of_inputs = dict()
additional_options = ['Update Automatically'] additional_options = ['Update Automatically']
app.layout = html.Div([ app.layout = html.Div([
...@@ -25,7 +25,7 @@ app.layout = html.Div([ ...@@ -25,7 +25,7 @@ app.layout = html.Div([
]), ]),
# Layer 2: For the checklist and Remove-/Start-Buttons # Layer 2: For the checklist and Remove-/Start-Buttons
html.Div([ html.Div([
dcc.Checklist(id='input-checklist',labelStyle = dict(display='block'),value=[]), dcc.Checklist(id='input-checklist',options=[],labelStyle = dict(display='block'),value=[]),
html.Button(id='clear-all-button',children='Clear All'), html.Button(id='clear-all-button',children='Clear All'),
html.Button(id='clear-selected-button',children='Clear Selected'), html.Button(id='clear-selected-button',children='Clear Selected'),
html.Button(id='start-button',children='Generate Graph') html.Button(id='start-button',children='Generate Graph')
...@@ -54,35 +54,41 @@ input-string is required as Output to clear the input box after each input ...@@ -54,35 +54,41 @@ input-string is required as Output to clear the input box after each input
Input('input-string','value'), Input('input-string','value'),
Input('clear-all-button','n_clicks'), Input('clear-all-button','n_clicks'),
Input('clear-selected-button','n_clicks'), Input('clear-selected-button','n_clicks'),
State('input-checklist','options'),
State('input-checklist','value') State('input-checklist','value')
) )
def update_input_checklist(input_value,btn1,btn2,all_values): def update_input_checklist(input_value,btn1,btn2,all_inputs,selected_inputs):
''' '''
:param input_value: given by dcc.Input :param input_value: given by dcc.Input
:type input_value: string :type input_value: string
:param btn1: signals pressing of clear-all-button :param btn1: signals pressing of clear-all-button
:param btn2: signals pressing of clear-selected-button :param btn2: signals pressing of clear-selected-button
:param all_values: values of all checked elements :param all_inputs: all labels and values from the checklist,
:type all_values: list of strings regardless if they have been checked or not
:type all_inputs: list of dictionaries with 2 entries each
:param selected_inputs: values of all checked elements
:type selected_inputs: list of strings
''' '''
changed_id = [p['prop_id'] for p in callback_context.triggered][0] changed_id = [p['prop_id'] for p in callback_context.triggered][0]
# if clear-all-button was pressed: # if clear-all-button was pressed:
if 'clear-all-button' in changed_id: if 'clear-all-button' in changed_id:
list_of_inputs.clear() app.layout['input-checklist'].options.clear()
return list(),list(),'' return list(),list(),''
# if clear-selected-button was pressed: # if clear-selected-button was pressed:
if 'clear-selected-button' in changed_id: if 'clear-selected-button' in changed_id:
for value in all_values: all_inputs = [i for i in all_inputs if i['value'] not in selected_inputs]
del list_of_inputs[value] return all_inputs,list(),''
return [{'label': i, 'value': i} for i in list_of_inputs],list(),''
# when the programm is first started: # when the programm is first started:
if input_value == '': if input_value == '':
list_of_inputs.clear() app.layout['input-checklist'].options.clear()
return list(),list(),'' return list(),list(),''
# when a new element is added via dcc.Input # when a new element is added via dcc.Input
if input_value not in list_of_inputs: options = copy.copy(app.layout['input-checklist'].options)
list_of_inputs[input_value] = input_value options = all_inputs
return [{'label': i, 'value': i} for i in list_of_inputs],all_values,'' currValues = [x['value'] for x in options]
if input_value not in currValues:
options.append({'label':input_value, 'value':input_value})
return options,selected_inputs,''
''' '''
This callback shows and hides the (first) help-box This callback shows and hides the (first) help-box
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment