Python Dash 数据表:行选择不起作用

Python Dash Datatable : Row selection Not working

嘿!这就是我的 table。 My Dash Code output

我想在 python 控制台中打印 selected 行的 NGID 值。 我已经创建了回调函数。但是当我 select 行时它什么都不做

这是我的布局代码:

 def dasher():
             df = pd.read_csv('wyjebany.csv')

             df = df[~df.HOME.str.contains('Beach|Futsal')]
             df = df[~df.COUNTRY.str.contains('Germany Oberliga NOFV|France  Youth U19 
                       League|Portugal Champions NACIONAL Juniores A 1|Spanish Bizkaia-Tercera')]
            df = df.replace(to_replace='Division|League|Liga|Footbal|Primavera', value='', 
                       regex=True)
                       # df = df.replace(to_replace='.', value='', regex=True)
            print(df)
            print(df.columns)

           app.layout = dash_table.DataTable(

                            columns=[{"name": i, "id": i} for i in df.columns],
                           row_selectable='multi',
                           sort_action='native',
                          # editable=True,
                          row_deletable=True,
                         # rows=[{}],
                         selected_rows=[],

                       css=[{'selector': 'tr:hover',
                       'rule': 'background-color:  #80FF80',
                            # 'font-family': 'Times New Roman',

                                   }],
                     html.Div(id='hidden-div', style={'display': 'none'},
             ),

这里是回调函数的代码

@app.callback(
dash.dependencies.Output('hidden-div', 'style'),
[dash.dependencies.Input('table', 'columns'),
dash.dependencies.Input('table', 'selected_rows')])
def print_value(columns,selected_rows):
     print("Hi i am triggered")
     # for i in selected_rows:
     #     print(i)
     selected_rows = [columns[i] for i in selected_rows]
     # selected_rows = pd.DataFrame(rows).iloc[i]
     print(selected_rows)
     style = {'display': 'none'}
     return style

使用 derived_virtual_selected_rows 而不是 selected_rows

对我有用