Skip to content

Calbacks that return a tuple inside a list to DIV children does not work and does not provide good error info #639

@hobob0t

Description

@hobob0t

When returning a list containing a tuple to a div child, the whole page will break and callbacks will stop.
This is OK, but the error that's returned does not provide good feedback on the actual problem. Would be nice if dash raised an error that says "hey stop putting weird data types inside other weird data types"

So this format works:

[string, string, html.Br(),string…etc]

this does NOT work:

[string, string,tuple, html.Br(),…etc]

To replicate:

Run this code and try and put garbage data into the editable table. like "fdsafdsafds" or something.
This will trigger the exception and try and return a list in the format ['test',html.Br(),'test',e.args] and the page will break because e.args is a tuple

import dash
from dash.dependencies import Input, Output,State
import dash_table
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd

app = dash.Dash(__name__)

params = [
    'Weight', 'Torque', 'Width', 'Height',
    'Efficiency', 'Power', 'Displacement'
]

app.layout = html.Div(id='wrapper', children=[
    dash_table.DataTable(
        id='table-editing-simple',
        columns=(
            [{'id': 'Model', 'name': 'Model'}] +
            [{'id': p, 'name': p} for p in params]
        ),
        data=[
            dict(Model=i, **{param: 0 for param in params})
            for i in range(1, 5)
        ],
        editable=True
    ),

    dcc.Graph(id='table-editing-simple-output'),
    html.Button('Ifdsafdsa',id='input')
])


def checkThisValue(value):
    if float(value)>100:
        value=100
    elif float(value)<0:
        value=0
    return value


@app.callback(
    Output('wrapper', 'children'),[Input('input','n_clicks')],
    [State('table-editing-simple', 'data'), State('table-editing-simple', 'columns')])
     
def display_output(n_clicks,rows, columns):
    try:
        for row in rows:
            for key,value in row.items():
                print(checkThisValue(value))
    except Exception as e:
        message=['test',html.Br(),'test',e.args] #e.args is a tuple so this will break
        return(message)

            
    df = pd.DataFrame(rows, columns=[c['name'] for c in columns])
    return [
    dash_table.DataTable(
        id='table-editing-simple',
        columns=columns,
        data=rows,
        editable=True
    ),

    dcc.Graph(id='table-editing-simple-output',figure={
        'data': [{
            'type': 'parcoords',
            'dimensions': [{
                'label': col['name'],
                'values': df[col['id']]
            } for col in columns]
        }]
    }),
    html.Button('Ifdsafdsa',id='input')
]


if __name__ == '__main__':
    app.run_server(debug=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions