Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Dash Datatable : Row selection Not working

Hey there!this is the look of my table. My Dash Code output

i want to print the NGID value of selected rows in python console. I have created callback function. But when i select the row it do nothings

This is the code for my layout:

 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'},
             ),

and here is the code for callbackfunction

@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
like image 820
Aaqib Mehrban Avatar asked Dec 10 '19 15:12

Aaqib Mehrban


1 Answers

Use derived_virtual_selected_rows instead of selected_rows.

It worked for me

like image 67
amirhossein Avatar answered Nov 02 '22 19:11

amirhossein