调整 plotly-Dash 表格列宽度

4
我想调整由Pandas Dataframe创建的Dash表格中列的宽度。该表格有3列: Path Scenario Step 我想将第一列(Path)的列宽设置为10%,第二列(Scenario)的列宽设置为40%,最后一列(Step)的列宽设置为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%'},
                ],
        ),
1个回答

2

按照文档中所建议的方式重新定义您的表格 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()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接