Datable o.weights[e] is undefined

Hi everyone,

(edit: Just wanted to clarify that I am just looking for an explanation to what the error means to debug my code, not for a solution :slight_smile:)

I have been getting a weird error that I seem to be unable to replicate to publish a minimum viable code here, thus I am looking for a general understanding of what that means. When sending back a df.to_dict(‘records’),
with back-end paging in python, if I add the options for multi selection (row_selectable=“multi” and selected_row=[]), I get the following error (edit: when I don’t add multi selection the table works):

“o.weights[e] is undefined”

What does that error mean? Cannot find anything online

I am doing the following in the code

className=“nine columns chart_div”,
columns=[],#[{“name”: i, “id”: i} for i in df.columns],


                                                        #action on table



@app.callback([Output(component_id=‘apg_ppg_table’, component_property=‘data’),Output(component_id=‘apg_ppg_table’, component_property=‘columns’)]
,[Input(‘button_filtering’, ‘n_clicks’),Input(‘additional_columns_table’, ‘value’),Input(‘apg_ppg_table’, “page_current”), Input(‘apg_ppg_table’, “page_size”),Input(‘apg_ppg_table’, “sort_by”),Input(‘apg_ppg_table’, ‘filter_query’)],)

def update_table(n_clicks,name_cols_to_show,page_current,page_size,sort_by,query):
df = find_in_table(df,query.split(’ && '))
df = sort_table(df,sort_by)
page_current = min(page_current,max(round(len(df)/page_size)-1,0))
df = df.loc[page_current*page_size:(page_current+ 1)*page_size,cols_to_show].reset_index(drop=True) #this reset index should be useless rn
data_table_columns = [columns_type_dict[i] for i in df[cols_to_show].columns]
return [df.to_dict(‘records’),data_table_columns]

Where sort_table and find_in_table are taken from the datatable walkthrough (find_in_table == filtering action, just in a separate function)

1 Like

Just wanted to clarify that I am just looking for an explanation to what the error means to debug my code, not for a solution :slight_smile:

I ended up finding the solution to this error.

It happens because of the following snippet of code:

columns=[],#[{“name”: i, “id”: i} for i in df.columns],

which conflicts with the row_selectable=“multi” argument.

I suspect row_selectable counts/needs the (number?) rows of the data to create the selectable row. Passing an empty dataframe must not be accounted for properly and creates a problem which prevents the creation of the table.

Very simple work-around it is just to initialize the data or pass the entire table as a children of that function.



Would you mind explaining your solution a bit more clearly?

I had a similar error but I believe the cause is not the exact same.

A better understanding of your solution may help me solve it.

Thank you

since I am passing an empty data frame (which by definition has no rows), the row_selectable=“multi” cannot create the click button you see on the side of the table.

I am assuming the code for the creation of the clickable thing on the side prevents the creation of the table.

My solution was to simply pass it real data and have the table updated with what I wanted via callback

I had the same error. Thanks to your explanation, I could finally find the source. I had an initially empty table and that didn’t get along well with the
row_deletable=True attribute of the data table.

Instead of prefilling the table with real data, I listed in my callback the ‘row_deletable’ attribute of the table as an output and return True. That way ‘row_deletable’ is set only after data has arrived.
Looks like this:

    [Output('mytable', 'columns')
     Output('mytable', 'data'),
     Output('mytable', 'row_deletable')],
    [Input('someinput', 'stuff')]
def generate_table(input):
    # somehow make a dataframe out of your input
    df = make_somehow_df(input)
    columns = [{“name”: i, “id”: i} for i in df.columns]
    data = df.to_dict(‘records’)
    return columns, data, True     # True is the value for mytable's row_deletable attribute

Many thanks @lemon for pointing out the reason of the error.

Hi, I had a similar problem that was due to the first callback being fired by the app itself. This callback received no data and the solution was to prevent the update by raise dash.PreventUpdate that was called conditional on not receiving any data. I am far from being any expert in any of this, so please tell me if that is a silly way out, but at least it worked in my case.

best wishes,