我有一个如下面的 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
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
)
输出:关于python - 如何减少 Dash DataTable 的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65625553/