I’m trying to create a multiple index (merge header) dash datatable and format it with style_data_conditional
but it did not work.
I tried something as below:
from dash import Dash, dash_table
import pandas as pd
app = Dash(__name__)
app.layout = dash_table.DataTable(
columns=[
{"name": ["", "Year"], "id": "year"},
{"name": ["City", "Montreal"], "id": "montreal"},
{"name": ["City", "Toronto"], "id": "toronto"},
{"name": ["City", "Ottawa"], "id": "ottawa"},
{"name": ["City", "Vancouver"], "id": "vancouver"},
{"name": ["Climate", "Temperature"], "id": "temp"},
{"name": ["Climate", "Humidity"], "id": "humidity"},
],
data=[
{
"year": i,
"montreal": i * 10,
"toronto": i * 100,
"ottawa": i * -1,
"vancouver": i * -10,
"temp": i * -100,
"humidity": i * 5,
}
for i in range(10)
],
merge_duplicate_headers=True,style_data_conditional=[
{
'if': {
'filter_query': '{{{col}}} < 1'.format(col=col),
'column_id': col
},
'backgroundColor': '#B10DC9',
'color': 'white'
} for col in df.columns
]
)
if __name__ == '__main__':
app.run_server(debug=False)
So I have 2 questions need your suggestions:
- Is there any way to style dataframe in pandas first then use this style to pass to dash datatable?
- Is there any way to
style_data_conditional
with dataframe that has multiple index.
Thank you.