【问题标题】:How to Reduce width of Dash DataTable如何减小 Dash DataTable 的宽度
【发布时间】:2021-01-08 08:23:06
【问题描述】:

我有一个如下所示的 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")

我的数据表看起来像:

【问题讨论】:

    标签: python datatable plotly-dash


    【解决方案1】:

    根据DataTabledocumentation有一个参数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
    )
    

    输出:

    【讨论】:

      猜你喜欢
      • 2023-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-18
      相关资源
      最近更新 更多