Show n tables depending on the length of a list of pandas dataframes (Python)

Hello,

I’m very new to dash and html. I have a list where each entry is a pandas dataframe, and which vary in length from time to time. I want to make some kind of report using dash, that shows all the dataframes in tables.

Lets says the list is df_all =[ df1,df2,df3,…]:

The code looks like

import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go

external_stylesheets = [‘https://codepen.io/chriddyp/pen/bWLwgP.css’]

app = dash.Dash(name, external_stylesheets=external_stylesheets)

colors = {
‘background’: ‘#111111’,
‘text’: ‘#7FDBFF
}

all_df = [df1, df]

def generate_table(dataframe, max_rows=10):
return html.Table(
# Header
[html.Tr([html.Th(col) for col in dataframe.columns])] +

    # Body
    [html.Tr([
        html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
    ]) for i in range(min(len(dataframe), max_rows))]
)

app.layout = html.Div(children=[

some loop like

    for i in range(len(all_df)):
        generate_table(all_df[i])

])

if name == ‘main’:
app.run_server(debug=True)

Please take a look at the documentation for Dash DataTable https://dash.plot.ly/datatable

1 Like