Newer
Older
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import dash
from dash import dcc
from dash import html
from dash.dependencies import Input, Output, State
import base64
import re
app = dash.Dash(__name__)
list_of_inputs = dict()
app.layout = html.Div([
html.H4("Add all lines in a file to a list"),
html.Div([
dcc.Upload(
id="upload-data",
children=html.Div(
["Drag and drop or click to select a file to upload."]
),
style={
"width": "30%",
"height": "60px",
"lineHeight": "60px",
"borderWidth": "1px",
"borderStyle": "dashed",
"borderRadius": "5px",
"textAlign": "center",
"margin": "10px",
}),
]),
dcc.Checklist(id='input-checklist',options=list(),labelStyle = dict(display='block'),value=[]),
])
@app.callback(
Output('input-checklist','options'),
Input('upload-data','filename'),
Input('upload-data','contents'),
State('input-checklist','options')
)
def update_input_list(uploaded_filenames,uploaded_file_contents,all_inputs):
if uploaded_file_contents is not None:
string = uploaded_file_contents
#cutting the first part of the String away to decode
found = base64.b64decode(re.search(',(.+?)$', string).group(1))
print(found.decode('utf-8'))
uploaded_file_contents = found.decode('utf-8')
list_of_inputs = (uploaded_file_contents.split())
#das hier sollte es untereinander anzeigen, bekomme ich allerdings nicht auf die Seite...
#return (*list_of_inputs, sep="\n")
options = all_inputs
if not options:
options = list()
CurrValues = [x['value'] for x in options]
# würde auch funktionieren
# return (found.decode('utf-8'))
for i in list_of_inputs:
if i not in CurrValues:
options.append({'label':i, 'value':i})
return options
if __name__ == '__main__':
app.run_server(debug=True)