-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathusage.py
74 lines (58 loc) · 1.79 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import uuid
import sys
import dash_uploader as du
import dash
if du.utils.dash_version_is_at_least("2.0.0"):
from dash import html # if dash <= 2.0.0, use: import dash_html_components as html
else:
import dash_html_components as html
from dash.dependencies import Output
app = dash.Dash(__name__)
UPLOAD_FOLDER_ROOT = r"C:\tmp\Uploads" if sys.platform.startswith("win") else "/tmp/Uploads"
du.configure_upload(app, UPLOAD_FOLDER_ROOT)
def get_upload_component(id):
return du.Upload(
id=id,
text="Drag and Drop files here",
text_completed="Completed: ",
cancel_button=True,
pause_button=True,
max_file_size=130, # 130 MB
max_total_size=350,
# filetypes=["csv", "zip"],
upload_id=uuid.uuid1(), # Unique session id
max_files=10,
)
def get_app_layout():
return html.Div(
[
html.H1("Demo"),
html.Div(
[
get_upload_component(id="dash-uploader"),
html.Div(id="callback-output"),
],
style={ # wrapper div style
"textAlign": "center",
"width": "600px",
"padding": "10px",
"display": "inline-block",
},
),
],
style={
"textAlign": "center",
},
)
# get_app_layout is a function
# This way we can use unique session id's as upload_id's
app.layout = get_app_layout
# 3) Create a callback
@du.callback(
output=Output("callback-output", "children"),
id="dash-uploader",
)
def callback_on_completion(status: du.UploadStatus):
return html.Ul([html.Li(str(x)) for x in status.uploaded_files])
if __name__ == "__main__":
app.run_server(debug=True)