-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload.py
executable file
·88 lines (80 loc) · 2.5 KB
/
upload.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import base64
import datetime
import io
import dash
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
colors = {
'background': '#FFFFFF',
'text': '#000000'
}
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
def parse_contents(contents, filename, date):
content_type, content_string = contents.split(',')
decoded = base64.b64decode(content_string)
try:
if 'csv' in filename:
# Assume that the user uploaded a CSV file
df = pd.read_csv(
io.StringIO(decoded.decode('utf-8')),
error_bad_lines = False)
elif 'xls' in filename:
# Assume that the user uploaded an excel file
df = pd.read_excel(
io.BytesIO(decoded),
error_bad_lines = False)
except Exception as e:
print(e)
return html.Div([
'There was an error processing this file.'
])
return html.Div([
html.H5(
children=['Opened file: ',filename],
style={
'textAlign': 'center',
'color': colors['text'],
'fontFamily': 'Roboto Condensed',
'fontSize': '18',
'fontWeight': 'normal',
}
),
html.H6(
children= ['Opened at: ',datetime.datetime.fromtimestamp(date)],
style={
'textAlign': 'center',
'color': colors['text'],
'fontFamily': 'Roboto Condensed',
'fontSize': '18',
'fontWeight': 'bold',
}
),
])
def UploadTextHTML():
return html.Div([
'\"Drag and Drop\" or ',
html.A('Select Files')
])
def UploadHTML(id_):
return html.Div([
dcc.Upload(
id=id_,
children= UploadTextHTML(),
style={
'width': '100%',
'height': '100%',
'lineHeight': '60px',
'borderWidth': '1px',
'borderStyle': 'dashed',
'borderRadius': '5px',
'textAlign': 'center',
'fontFamily': 'Roboto Condensed',
'fontSize': '18',
},
# Allow multiple files to be uploaded
multiple=True
),
html.Div(id='output-data-upload'),
])