I am getting a callback error
Schema: [<Output `output_filetype.children`>, <Output `output-data-upload.children`>]
Path: ()
Expected type: (<class 'tuple'>, <class 'list'>)
Received value of type <class 'NoneType'>:
None
I think the problem is in return of update_output() function.
import chart_studio as py
import plotly.graph_objs as go
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import pandas as pd
import json
import xlrd
import openpyxl
import dash
from dash import Dash, dcc, html, Input, Output, dash_table
from dash.dependencies import State
import plotly.express as px
import plotly.io as pio
import base64
import datetime
from dash import no_update
import io
pio.renderers.default = "browser"
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
dcc.Dropdown(['Excel Sheet', 'CSV File'], id='file_type', multi=False, style={'width': "40%"}),
html.Div(id='output_filetype', children=[]),
dcc.Upload(
id='upload-data',
children=html.Div([
'Drag and Drop or ',
html.A('Select Files')
]),
style={
'width': '100%',
'height': '60px',
'lineHeight': '60px',
'borderWidth': '1px',
'borderStyle': 'dashed',
'borderRadius': '5px',
'textAlign': 'center',
'margin': '10px'
},
# Allow multiple files to be uploaded
multiple=False
),
html.Div(id='output-data-upload'),
])
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')))
elif 'xls' in filename:
# Assume that the user uploaded an excel file
df = pd.read_excel(io.BytesIO(decoded))
except Exception as e:
print(e)
return html.Div([
'There was an error processing this file.'
])
return html.Div([
html.H5(filename),
html.H6(datetime.datetime.fromtimestamp(date)),
dash_table.DataTable(
df.to_dict('records'),
[{'name': i, 'id': i} for i in df.columns]
),
html.Hr(), # horizontal line
# For debugging, display the raw contents provided by the web browser
html.Div('Raw Content'),
html.Pre(contents[0:200] + '...', style={
'whiteSpace': 'pre-wrap',
'wordBreak': 'break-all'
})
])
@app.callback(
[Output('output_filetype', 'children'),
Output('output-data-upload', 'children')],
[Input(component_id='file_type', component_property='value'),
Input('upload-data', 'contents')],
[State('upload-data', 'filename'),
State('upload-data', 'last_modified')],
)
def update_output(value, contents, names, dates):
container = "{}".format(value)
if contents is not None:
children = [
parse_contents(c, n, d) for c, n, d in
zip(contents, names, dates)]
return container, children
if __name__ == '__main__':
app.run_server(debug=True)