The example is a significantly reduced version of my app.
The app functions correctly but upon initiation, it throws the traceback below.
I am attempting to return a tuple of dcc.Download
to two different Outputs. I have tried unpacking the tuple and putting each element in the return
as well but still get the same error.
What I don’t understand is how it states that I am returning a None
type, when I am actually returning a tuple.
Traceback:
dash._grouping.SchemaTypeValidationError: Schema: [<Output `rprt1.data`>, <Output `rprt2.data`>]
Path: ()
Expected type: (<class 'tuple'>, <class 'list'>)
Received value of type <class 'NoneType'>: None
Functioning Code:
import dash
from dash import html, Input, Output
from dash import dcc
import pandas as pd
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Download(id='rprt1'),
dcc.Download(id='rprt2'),
html.Button('A', id='button', n_clicks=0)
])
def multi_dnwld(df1, df2, names):
tup = (df1, df2)
dwnld = []
for df, name in zip(tup, names):
filename = name + ' - ' + '.csv'
dwnld.append(dcc.send_data_frame(df.to_csv, filename, index=False))
dwnld = tuple(dwnld)
return dwnld
df1 = pd.DataFrame([[1,2],[3,4]], columns = ['a', 'b'])
df2 = pd.DataFrame([[1,2],[3,4]], columns = ['a', 'b'])
@app.callback(
Output('rprt1', 'data'),
Output('rprt2', 'data'),
Input('button', 'n_clicks'),
prevent_initial_callback=True
)
def summary(n_clicks):
if n_clicks>0:
names = ['Sum1', 'Sum2']
return multi_dnwld(df1, df2, names)
if __name__ == '__main__':
app.run_server(debug=True)