python - 如何减少 Dash DataTable 的宽度

标签 python datatable plotly-dash

我有一个如下面的 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")
我的数据表看起来像:
enter image description here

最佳答案

根据DataTable documentation有争论fill_width :

... False: The table container's width will equal the width of its content.


将此参数设置为 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
)
输出:
Result

关于python - 如何减少 Dash DataTable 的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65625553/

相关文章:

python - 如何从提取的帧中制作视频?

python - 将多个 PDF 合并为一个 PDF

c# - 检查表是否包含重叠的时间跨度

python - 阴谋冲刺 : Hide/show slider component by updating different dropdown component

python - 运行 Dash 应用程序时名称或服务未知

python - Django 自然键,两个值的组合?

javascript - 如何在 python 中使用 selenium 和 javascript 跟踪鼠标事件和位置?

jsf - :commandButton not working inside h:dataTable

javascript - HTML 表格中的 "Endless scrolling"效果

python - 如何在 dash 网络应用程序上显示 wordcloud 图像