如何在绘图破折号框架中居中对齐表格?

pr07ecH70r

我是 dash 的新手,并试图将我用函数创建的表格居中对齐。我已经从 SQL DB 中获取的表数据。在破折号布局中,我尝试为表格本身使用样式,但它不起作用。样式仅适用于页面上的文本。Df 是我没有发布的数据框,因为它与样式无关。我需要在布局中应用样式还是在函数中创建表格时应用样式?

非常感谢!

def generate_table(dataframe, max_rows=1000):
    return html.Table([
        html.Thead(
            html.Tr([html.Th(col) for col in dataframe.columns])
        ),
        html.Tbody([
            html.Tr([
                html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
            ]) for i in range(min(len(dataframe), max_rows))
        ])
    ])


app.layout = html.Div(children=[
    html.H2(
        children='Products',
        style={
            'textAlign' : 'center' 
        }
    ),
    generate_table(df)
])
丹尼尔·R

一个简单的解决方法是添加style={'marginLeft': 'auto', 'marginRight': 'auto'}html.Table. 所以你的功能会变成:

def generate_table(dataframe, max_rows=1000):
    return html.Table([
        html.Thead(
            html.Tr([html.Th(col) for col in dataframe.columns])
        ),
        html.Tbody([
            html.Tr([
                html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
            ]) for i in range(min(len(dataframe), max_rows))
        ])
    ], style={'marginLeft': 'auto', 'marginRight': 'auto'})

一个更好的主意是className="center"将以下内容添加并添加到.css文件中:

.center {
  margin-left: auto;
  margin-right: auto;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在绘图破折号中更改图像大小

如何在Windows 7/8中键入破折号和破折号?

破折号实时绘图

如何在shell中重复破折号(连字符)

如何在Flutter中添加破折号

如何在QSpinBox中绘制破折号而不是null?

如何在Qt标签中显示破折号?

如何在13.04中更改破折号?

如何在表格中居中对齐项目

如何从Google表格中的数据中删除破折号,然后执行forEach循环

如何使破折号/连字符不破坏表格中的单词

在一个单元格中使用多行以绘图破折号打印表格

按钮和破折号未对齐

如何在sh(破折号)中列出脚本中声明的变量?

如何在Powershell中处理属性名称中的破折号

在表达中,如何在带有破折号的表单中获取属性名称?

在printf中的破折号

如何写破折号和破折号?

如何在python中打印没有任何空格的破折号

如何在 CosmosDB SqlAPI 中查询带有破折号的属性?

如何在数字KeyboardType中隐藏点和破折号

如何在13.10的破折号中搜索手册页?

C#如何在命令行参数中实现破折号“-”选项?

如何在bash printf的格式字符串中包含破折号?

如何在php搜索栏中忽略破折号和逗号

如何在bash脚本中多次使用带有“-”(破折号)的标准输入?

如何在PHP Laravel中删除特殊字符,但字符“ñ/Ñ”和破折号“-”除外

如何在Matlab的文本文件中的两行上读取破折号?

如何在统一破折号中启用一键打开?