Reputation: 6159
I have a dash.datatable like below a but the column width is too long for my values, the column width should be limited to the maximum length word of the respective column.
my code:
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")
My DataTable looks like:
Upvotes: 15
Views: 17049
Reputation: 1275
According to the DataTable
documentation there is an argument fill_width
:
... False: The table container's width will equal the width of its content.
Setting this argument to 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
)
Output:
Upvotes: 27