Bold the text the last row of dash data-table

Viewed 1157

I have created a web application in Plotly which amongst other things, displays a range of different DataTables.

Is there a simple way to add conditional formatting to change the last row to bold font?

I basically want to highlight the last row as an average row but do not have anything to reference in a filter, apart the the fact it is the last row of the table.

Thank you

enter image description here

1 Answers

You could use style_data_conditional and row_index and do something like this:

from dash import Dash
import pandas as pd
from dash_table import DataTable

df = pd.DataFrame({"A": [1, 2, 3, 4, 5], "B": [1, 2, 3, 4, 5], "C": [1, 2, 3, 4, 5]})

app = Dash()

app.layout = DataTable(
    data=df.to_dict("records"),
    columns=[{"name": column, "id": column} for column in df.columns],
    style_data_conditional=[
        {
            "if": {"row_index": len(df) - 1},
            "fontWeight": "bold",
        },
    ],
)

if __name__ == "__main__":
    app.run_server()

Based on the first example listed in the documentation here

Related