【发布时间】:2022-02-11 02:37:08
【问题描述】:
我想在 Dash DataTable 中将标题向左对齐。我使用 Dash DataTable documentation 中的示例代码。然后我按照DataTable reference 中的建议实现了style_header 字典。
from dash import Dash, dash_table
import pandas as pd
from collections import OrderedDict
data = OrderedDict(
[
("Date", ["2015-01-01", "2015-10-24", "2016-05-10", "2017-01-10", "2018-05-10", "2018-08-15"]),
("Region", ["Montreal", "Toronto", "New York City", "Miami", "San Francisco", "London"]),
("Temperature", [1, -20, 3.512, 4, 10423, -441.2]),
("Humidity", [10, 20, 30, 40, 50, 60]),
("Pressure", [2, 10924, 3912, -10, 3591.2, 15]),
]
)
df = pd.DataFrame(data)
app = Dash(__name__)
app.layout = dash_table.DataTable(
data=df.to_dict('records'),
columns=[{'id': c, 'name': c} for c in df.columns],
style_header={'textAlign': 'left'},
style_cell={'textAlign': 'left'}
)
if __name__ == '__main__':
app.run_server(debug=True)
我希望与 style_cell 中的行为相同,但它没有效果,列左对齐,标题右对齐。我不确定,但自从我更新到 Dash 2.1.0 后我就想到了。如何将标题左对齐?
【问题讨论】:
标签: python datatable alignment plotly-dash