gpt4 book ai didi

python - 如何减少 Dash DataTable 的宽度

转载 作者:行者123 更新时间:2023-12-03 23:01:14 25 4
gpt4 key购买 nike

我有一个如下面的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com