我想调整Dash表(从Pandas Dataframe创建)中列的宽度。表中有3列:路径方案步骤
我想将第一列(路径)的列宽设置为10%,将第二列(方案)的列宽设置为40%,将最后一列(步骤)的列宽设置为50%。
我正在运行下面的代码,但是列宽的更改并没有像预期的那样起作用。"Path“列占用了超过50%的宽度,而"Steps”列占用了大约20%的宽度。数据帧名称为dfSteps
columns=[{"name": i, "id": i} for i in dfSteps.columns],
data=dfSteps.to_dict('records'),
style_header={
'backgroundColor': 'rgb(230, 230, 230)',
'fontWeight': 'bold'
},
style_table={
'maxWidth': '2000px',
'overflowX': 'scroll',
'border': 'thin lightgrey solid'
},
style_cell={
'font_family': 'cursive',
'font_size': '16px',
'border': '1px solid grey',
'minWidth': '1px', 'width': 'fixed', 'maxWidth': '1000px',
'textAlign': 'left', 'whiteSpace': 'normal'
},
style_cell_conditional=[
{'if': {'column_id': 'Path'},
'width': '10%'},
{'if': {'column_id': 'Scenario'},
'width': '40%'},
{'if': {'column_id': 'Path'},
'width': '50%'},
],
),发布于 2021-02-01 05:50:48
只需按照documentation https://plotly.com/python/table/中的建议重新定义您的表
fig = go.Figure(data=[go.Table(
columnorder = [1,2],
columnwidth = [80,400],
header = dict(
values = [['<b>EXPENSES</b><br>as of July 2017'],
['<b>DESCRIPTION</b>']],
line_color='darkslategray',
fill_color='royalblue',
align=['left','center'],
font=dict(color='white', size=12),
height=40
),
cells=dict(
values=values,
line_color='darkslategray',
fill=dict(color=['paleturquoise', 'white']),
align=['left', 'center'],
font_size=12,
height=30)
)
])
fig.show()https://stackoverflow.com/questions/65965585
复制相似问题