Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CiS Projekt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ockenden, Samuel
CiS Projekt
Commits
5a78e24d
Commit
5a78e24d
authored
3 years ago
by
David, Sebastian
Browse files
Options
Downloads
Patches
Plain Diff
Added option for automatical updates, changed some variable names
parent
ba9f8f3c
No related branches found
No related tags found
1 merge request
!8
UI Hinzufügen
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ui_programm_fragmente/input_to_checklist.py
+30
-15
30 additions, 15 deletions
ui_programm_fragmente/input_to_checklist.py
with
30 additions
and
15 deletions
ui_programm_fragmente/input_to_checklist.py
+
30
−
15
View file @
5a78e24d
...
...
@@ -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_
check
list
(
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_
option
s: all labels and values from the checklist,
:param all_
input
s: all labels and values from the checklist,
regardless if they have been checked or not
:type all_
option
s: list of dictionaries with 2 entries each
:param
all_value
s: values of all checked elements
:type
all_value
s: list of strings
:type all_
input
s: list of dictionaries with 2 entries each
:param
selected_input
s: values of all checked elements
:type
selected_input
s: 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_
option
s
)):
x
=
all_
option
s
[
i
][
'
value
'
]
if
x
in
all_value
s
:
for
i
in
range
(
len
(
all_
input
s
)):
x
=
all_
input
s
[
i
][
'
value
'
]
if
x
in
selected_input
s
:
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment