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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hobob0t opened this issue Mar 8, 2019 · 1 comment

Comments

@hobob0t
Copy link

hobob0t commented Mar 8, 2019

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)
@alexcjohnson
Copy link
Collaborator

Thanks @hobob0t - this should be solved by #452, whenever we manage to finish that effort!

@hobob0t hobob0t closed this as completed Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants