如何减少DashDataTable的宽度

我有一个如下所示的 dash.datatable,但列宽对于我的值来说太长,列宽应限制为相应列的最大长度字。

我的代码:

app = JupyterDash(__name__)

df = pd.DataFrame(
{
    "A" : ["one","two","three"],
    "B" : ["one","two","three"],
    "C" : ["one","two","three"],
    
}
)
app.layout = dash_table.DataTable(
    data=df.to_dict('records'),
    columns=[{'id': c, 'name': c} for c in df.columns],
    style_data={
        'whiteSpace': 'normal',
        'height': 'auto',
    },
    
)

if __name__ == "__main__":
    app.run_server(mode="jupyterlab")

我的数据表看起来像:

回答

根据DataTable 文档,有一个论点fill_width

... False:表格容器的宽度将等于其内容的宽度。

将此参数设置为False

app.layout = dash_table.DataTable(
    data=df.to_dict('records'),
    columns=[{'id': c, 'name': c} for c in df.columns],
    style_data={
        'whiteSpace': 'normal',
        'height': 'auto',
    },
    fill_width=False
)

输出:


以上是如何减少DashDataTable的宽度的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>