Datatable will not update with dropdown or callback is not working?

New to Plotly .
Is there a way to check if a callback is triggered?
I believe my callback is not working or is not triggered.

Table

    dash_table.DataTable(
        id='datatable-id',
        columns=[
            { "id": i,
                    "deletable": False, "selectable": True} for i in df.columns],
        data = df.to_dict('records'),
        editable=False,
        page_action="native",
        page_current=0,
        page_size=5,
        filter_action="native",
        sort_action="native",
        sort_mode="multi",
        style_header={
             'backgroundColor': 'rgb(230, 230, 230)',
             'fontWeight': 'bold'
         },
        style_data_conditional=[        
             {
                 'if': {'row_index': 'odd'},
                 'backgroundColor': 'rgb(248, 248, 248)'
             }
         ],
    )])

Callback

@app.callback([Output('datatable-id','data'),
              Output('datatable-id','columns')],
               [Input('dropdown', 'value')]
             )
def update_dashboard(filter_type):
    if filter_type is None:
        raise PreventUpdate
    else:
        dff = some data call 
        columns=[{"name": i, "id": i, "deletable": False, "selectable": True} for i in dff.columns]
        data=dff.to_dict('records')
        
        
        return (data,columns)

Th dropdown is able to update the pie chart.
Piechart callback

@app.callback(
    Output('graph-id', 'figure'),
    [Input('dropdown', 'value')]
)
def update_graph(my_dropdown):
   
    piechart=px.pie(
            data_frame=df, names=my_dropdown, hole=.0, title ="Title",  
            )

    return (piechart)

Any help, tips or tricks would be appreciated!

Hello @randomStudent,

Yes, there are a couple of ways to check to see if a callback has been triggered.

One way is to look at the network tab of whatever browser you are using, then look for a call of “_dash-update-component”. Inside of the payload you can check to see if your output is listed, here is a sample:

The other is to print to the python terminal during the function you are looking for.

Just to confirm, you do have a dropdown and its id is “dropdown”? You didnt list it above. :slight_smile:

1 Like

Wow thanks!

2 actions happen when the drop down is selected.
One is empty (datatable call)

The other is not. (pie chart)

Any idea why there is no response from the second call?

Thanks for the tips~

Edit to include dropdown

dropdown = html.Div([
    html.Label(['Choose Filter:'],style={'font-weight': 'bold', "text-align": "center"}),
    dcc.Dropdown(id = 'dropdown', *......*```

It’s weird that you arent seeing a request payload either…

Is that callback defined after the app is initiated?


Yes, even after the pie chart is does not work.

Just checking, but are you selecting a drop-down option?

Yes. Sorry for late reply.

Alright, make sure the filter_type is operating as expected on the python side, just add a print(filter_type) before your if clause.

Is your pie chart showing?

Thanks for all the help.
The pie chart is showing.
After changing the output to some simple text it works.
image

@app.callback(Output("first_output_1", "children"),
               [Input('dropdown', 'value')]
             )
def update_dashboard(filter_type):

        return (data, 'callback executed') 

But changing the output to the datatable and the text. it does not work
image

@app.callback([Output('datatable-id', "data")
              ,Output("first_output_1", "children")],
               [Input('dropdown', 'value')]
             )
def update_dashboard(filter_type):

        return (data, 'callback executed')```


Really scratching my head on this one.

Try swapping the () with [] in the second callback.

THANKS! Worked! :partying_face:

1 Like