Color-coding Tables


#1

Is there a way to change the color of specific cells based on the value within them in dt.DataTable?


#2

Though it is not specifically a dt.Datatable, I know you can do this by creating a plotly graph_objs.Table and put into your app.
(See last example in https://plot.ly/python/table/)

Maybe you can reuse some of the logic there? :slightly_smiling_face:


#3

unfortunately not. I need the tables to be editable as well, so i cannot use go.Table altogether :frowning:


#4

I have the same issue. I’m trying to add conditional color formatting to the datatable but it doesn’t seem to have that functionality. I also don’t like the filtering syntax I have to use for conditional formatting since I wish I could use normal python syntax for filtering since then I have the ability of being more complex with my conditions


#5

Why not use the style_data_conditional to change colour of certain cell? There’s an example from https://dash.plot.ly/datatable/style

dash_table.DataTable(
    data=df.to_dict('rows'),
    columns=[
        {'name': i, 'id': i} for i in df.columns
    ],
    style_data_conditional=[
        {
            'if': {
                'column_id': 'Region',
                'filter': 'Region eq "Montreal"'
            },
            'backgroundColor': '#3D9970',
            'color': 'white',
        },
        {
            'if': {
                'column_id': 'Humidity',
                'filter': 'Humidity eq num(20)'
            },
            'backgroundColor': '#3D9970',
            'color': 'white',
        },
        {
            'if': {
                'column_id': 'Temperature',
                'filter': 'Temperature > num(3.9)'
            },
            'backgroundColor': '#3D9970',
            'color': 'white',
        },
    ]
)