Return a Pandas DataFrame as a data_table from a callback with Plotly Dash for Python

前端 未结 2 931
半阙折子戏
半阙折子戏 2021-02-06 17:43

I would like to read a .csv file and return a groupby function as a callback to be displayed as a simple data table with \"dash_table\" library. @Lawliet\'s helpful answer shows

2条回答
  •  抹茶落季
    2021-02-06 18:36

    You almost got it done just with minor modification in update_datatable it should work fine (not tested):

    def update_datatable(n_clicks,csv_file):            
        if n_clicks:                            
            dfgb = df.groupby(['state']).sum()
            return html.Div([dash_table.DataTable(
                    data=dfgb.to_dict('rows'),
                    columns=[{'name': i, 'id': i} for i in dfgb.columns],
                    style_header={'backgroundColor': "#FFD700",
                                  'fontWeight': 'bold',
                                  'textAlign': 'center',},
                    style_table={'overflowX': 'scroll'},  
                    style_cell={'minWidth': '180px', 'width': '180px',
                            'maxWidth': '180px','whiteSpace': 'normal'},                        
                             filtering=True,
                     row_selectable="multi",
                     n_fixed_rows=1),
                   html.Hr()
            ])
    

提交回复
热议问题