Dash table formatting

Hi, just wondering when I will be able to customise a dash table (from dash-table-experiments)? Such as edit the cell colour, fonts etc.

Trying to decide between the table options and would love to use the dash table but seems I would have to compromise aesthetics for now.

Thanks

1 Like

see the following chat. This problem has been solved. In summary you can create a function to assign color to specific column entries based on set parameters. It can be included in the table creating function. The challenge would be defining your style function. This is covered in the chat.

Yes I’ve seen that already. Isn’t that referring to a HTML table? I’m interested in formatting a dash table.

My suggestion would be write a function to generate the style of the table like the following
COLORS = [
{
‘text’: ‘#008000
},
{
‘text’: ‘#040404
},
{
‘text’: ‘#f41111
},
]

def t_style(value):
    style = {
        'color': COLORS[1]['text']
    }
    return style

def sy_style(value):
    if value < = 0:
        style = {
            'color': COLORS[0]['text']
        }
    elif value == 0:
        style = {
            'color': COLORS[1]['text']
        }
    else:
        style = {
            'color': COLORS[2]['text']
        }
    return style

def text_style(valued):
    style = {}

    valued = float(value)
    if value > 0:
        style = {
            'color': COLORS[0]['text']
        }
    elif value == 0:
        style = {
            'color': COLORS[1]['text']
        }
    elif value < 0:
        style = {
            'color': COLORS[2]['text']
        }
    return style

def generate_table(dataframe):
    rows = []
    for i in range(len(dataframe)):
        row = []
        for col in dataframe.columns:
            value = dataframe.iloc[i][col]
            if  col== 'A':
                style = text_style(value)
                row.append(html.Td(value, style=style))
            else:
                style = t_style(value)
                row.append(html.Td(value, style=style))
        rows.append(html.Tr(row))

This way you can set an iteration that appends the style to the table entries. Though it might seem inefficient but you will get the color to the text unless I have missed you somewhere. The above code works for numbers. you can edit it for text and all

See Dash DataTable - Conditional Formatting