Hello guys,
I am quite new to Dash and frontend in general, how can I simply center a table using dash_table?
With my code, the table is always on the left of the page.
I am sorry if the question seems pretty basic, but I spent a lot of time in the web, and I did not find any solution…
Thanks guys!
Below is my code:
import dash
import dash_table
import pandas as pd
from collections import OrderedDict
import dash_bootstrap_components as dbc
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.Dash(name)
app.layout = dash_table.DataTable(
data=df.to_dict(‘records’),
columns=[{‘id’: c, ‘name’: c} for c in df.columns],
style_cell={‘padding’: ‘5px’, ‘textAlign’: ‘center’},
style_header={
‘backgroundColor’: ‘grey’,
‘fontWeight’: ‘bold’
},
style_data_conditional=[
{
'if': {'row_index': 'odd'},
'backgroundColor': 'rgb(120, 248, 248)'
}
], fill_width=False)
if name == ‘main’:
app.run_server(debug=True)