# Function with 2 return values is only considered 1 by callback

**URL:** <https://community.plotly.com/t/function-with-2-return-values-is-only-considered-1-by-callback/75599>\
**Category:** Dash Python\
**Tags:** question\
**Created:** [May 28, 2023, 1:33am UTC](https://community.plotly.com/t/function-with-2-return-values-is-only-considered-1-by-callback/75599 "2023-05-28T01:33:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrcnz](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@mrcnz](https://community.plotly.com/u/mrcnz)\
**Post date:** [May 28, 2023, 1:33am UTC](https://community.plotly.com/t/function-with-2-return-values-is-only-considered-1-by-callback/75599/1 "2023-05-28T01:33:20Z")

</div>

Good afternoon Dash community,  
When processing a CSV file, using substantially the boilerplate code provided by Dash for the Upload widget, I have added a path to `dcc.Store` (in `app.layout`) in addition to the printing of the CSV file using `dash_table.DataTable`. The `return` therefore has two return values, and this aligns with the `@app.callback` with two `Output`’s.  
Why then does Dash have a callback error when I am returning 2 outputs?

`dash._grouping.SchemaLengthValidationError: Schema: [<Output `raw\_df\_store.data`>, <Output `output-data-upload.children`>] Path: () Expected length: 2 Received value of length 1:`

`def parse\_contents(contents, filename):  
content = contents.split(‘,’)[1]  
decoded = base64.b64decode(content)

```
try:
    if 'csv' in filename:
        # Assume that the user uploaded a CSV file
        raw_df = pd.read_csv(
            io.StringIO(decoded.decode('utf-8')))
        raw_df_dict = raw_df.to_dict('records')

except Exception as exception:
    print(exception)
    return None, html.Div([
        f'There was an error processing this file. Exception - {exception}'
    ])

raw_df_print = html.Div([
    html.H5(f'File uploaded: {filename}'), 
    dash_table.DataTable(
        raw_df_dict,[{'name': i, 'id': i} for i in raw_df.columns]
    ),
])

return raw_df_dict, raw_df_print

```

@app.callback([Output(‘raw\_df\_store’, ‘data’),  
Output(‘output-data-upload’, ‘children’)],  
[Input(‘upload-data’, ‘contents’),  
State(‘upload-data’, ‘filename’)],  
prevent\_initial\_call=True  
)  
def update\_output(file\_content, filename):  
if file\_content is not None:  
filename = filename[0]  
return [parse\_contents(file\_content[0], filename)]

```
return None`

```

Examining the error, it seems that additional round brackets, (), are added before the outer list square brackets 's. Would it be these that are causing the issue? and if so, why would they be added and how do I exclude them before being passed to the callback?

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [May 28, 2023, 2:56am UTC](https://community.plotly.com/t/function-with-2-return-values-is-only-considered-1-by-callback/75599/2 "2023-05-28T02:56:04Z")

</div>

Hello @mrcnz,

Welcome to the community!

I think you should have your return value not be listed within the brackets. I am assuming that this is causing it to be treated as one entry in a list, verse two separate values.

---

<div class="post-metadata">

**Author:** ![mrcnz](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@mrcnz](https://community.plotly.com/u/mrcnz)\
**Post date:** [May 28, 2023, 4:32am UTC](https://community.plotly.com/t/function-with-2-return-values-is-only-considered-1-by-callback/75599/3 "2023-05-28T04:32:47Z")

</div>

Good afternoon  
Thank you for your response. I agree, however what I can work out is how to stop Dash including these brackets. When terminal printing the two return values they are lists of dictionaries as expected, but when examining the error output, they are encased in [( )]. Why would this be, and how to I work around this behaviour? I understand the outer list, it’s really the () I cannot understand.  
Kind regards and thank you

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [May 28, 2023, 11:35am UTC](https://community.plotly.com/t/function-with-2-return-values-is-only-considered-1-by-callback/75599/4 "2023-05-28T11:35:21Z")

</div>

Functions that return multiple values are a tuple.

> **[Return multiple values from a function in Python | Flexiple Tutorials](https://flexiple.com/python/python-return-multiple-values/#)**
>
> In this guide, we look at Python: Return multiple values from a function. We explain the various methods in detail and list their shortcomings.

In order to return it as a list, I would wrap the return value from the function in brackets, and remove the last brackets.

---

<div class="post-metadata">

**Author:** ![mrcnz](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@mrcnz](https://community.plotly.com/u/mrcnz)\
**Post date:** [May 28, 2023, 11:52pm UTC](https://community.plotly.com/t/function-with-2-return-values-is-only-considered-1-by-callback/75599/5 "2023-05-28T23:52:28Z")

</div>

Good morning @jinnyzor

Thank you so much for your input. After hunting, I found my error.  
In the following function, I was returning a list (I originally had `return [parse_contents(file_content[0], filename)]`).

The following now works as expected

`def update_output(file_content, filename): if file_content is not None: filename = filename[0] return parse_contents(file_content[0], filename)`

Thank you so much for the input.  
Kia Ora (both hello/thank you in Maori)
