如何将基于 html 组件的 table 转换为破折号数据 table

How to convert a html components-based table to dash Datatable

我用短划线 html 组件创建了一个 table(通过函数)。但是,我发现这种方法有一些局限性,即 - 我无法弄清楚如何将显示的行限制为仅 25 行,并将 table 拆分为页面。我已经看到破折号 Databale 提供了更多的灵活性。我还是个新手,发现部门分离有点笨拙。如何将我的代码(我的table)转换为数据table?

这是我的 table 生成函数:

def generate_table(dataframe, max_rows=10000):
    return html.Table([
        html.Thead(
            html.Tr([html.Th(col) for col in dataframe.columns])
        ),
        html.Tbody([
            html.Tr([
                html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
            ]) for i in range(min(len(dataframe), max_rows))
        ])
    ], style={
        'margin-right': 'auto',
        'margin-left': 'auto'
        }
    )

在布局中,我只是将我的 table 放到一个单独的 Div 中。这里没什么特别的。

html.Div(id='modulewafer-table', style={'text-align' : 'center'}),

我知道破折号 Datatable 的语法使用了 rows=''columns='' 词典。还是我错了。我可以使用现有函数将生成的值分配给这些属性吗?

根据评论进行跟进,因为代码不适合评论框,我正在复制最少的代码以从 here 的数据框创建破折号数据表,并进行微小的更改以反映您的名字

import dash
import dash_table
import pandas as pd

# here you would put the dataframe that features in your question as an argument to your function generate_table
df = dataframe

app = dash.Dash(__name__)

app.layout = dash_table.DataTable(
    id='table',
    columns=[{"name": i, "id": i} for i in df.columns],
    data=df.to_dict('records'),
)

if __name__ == '__main__':
    app.run_server(debug=True)