-
Notifications
You must be signed in to change notification settings - Fork 7
/
usage.py
59 lines (50 loc) · 1.39 KB
/
usage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import dash
from dash import Input, Output, State, html
from flowfunc import Flowfunc, config, jobrunner
def add(a: int, b: int):
"""Add two numbers"""
return a + b
def subtract(a: int, b: int):
"""Subtract one number from another"""
return a - b
flist = [
add,
subtract,
]
app = dash.Dash(__name__)
fconfig = config.Config.from_function_list(flist)
runner = jobrunner.JobRunner(fconfig)
app.layout = html.Div(
[
html.Button(id="btn_run", children=["Run"]),
html.Div(
Flowfunc(
id="nodeeditor",
config=fconfig.dict(),
disable_zoom=True,
type_safety=False,
),
style={"height": "500px", "width": "100%"},
),
html.Div(id="output"),
]
)
@app.callback(
[Output("output", "children"), Output("nodeeditor", "nodes_status")],
Input("btn_run", "n_clicks"),
State("nodeeditor", "nodes"),
)
def run(nclicks, nodes):
if not nodes:
return [], {}
output = runner.run(nodes)
output_html = []
nodes_status = {}
for node in output.values():
output_html.append(html.Div(f"{node.type}: {node.result}"))
if node.error:
output_html.append(html.Div(f"{node.error}"))
nodes_status[node.id] = node.status
return output_html, nodes_status
if __name__ == "__main__":
app.run_server(debug=True)