Is it possible to apply row by row number formatting in dash data table? Right now, style_data_conditional does not work in below code .
import dash
import dash_table
import pandas as pd
d = [[1, 2, 3], [5, 6, 7], [9, 10, 11], [12, 13, 14]]
df = pd.DataFrame(d, columns=["A", "B", "C"])
app = dash.Dash()
app.layout = dash_table.DataTable(
data=df.to_dict("records"),
columns=[{"name": col, "id": col} for col in df.columns],
style_data_conditional=[
# Apply 4 decimal places to the first row
{
"if": {"row_index": 0},
"textAlign": "right",
"numberFormat": ".4f",
},
# Apply 2 decimal places to the second row
{
"if": {"row_index": 1},
"textAlign": "right",
"numberFormat": ".2f",
},
# Apply a percentage format to the third row
{
"if": {"row_index": 2},
"textAlign": "right",
"numberFormat": ".2%",
},
# Apply a dollar format to the fourth row
{
"if": {"row_index": 3},
"textAlign": "right",
"numberFormat": "$,.2f",
},
],
)
app.run_server()