Style cell conditional background color gradient

Hello everybody,

I create a dash_table, and it gives the elections candidats with their vote percentage, I want to use linera gradient to colorize the cell regarding the percentage

my layout:
dcc.Tab(label=‘Elections Européennes 2019’, children=[
html.Div(id=“elections_table”, style={‘paddingLeft’:‘70px’})
and below my callback function

@app.callback(Output('elections_table','children'), [Input('ville-picker','value')])
def europeenes_table(selected_ville):
    code_insee = df[df['ville'] == selected_ville]['code_insee'].iloc[0][18:]
    liste_candidat = df_europe.columns[3:-5]

    donnees = [
        df_europe[df_europe['code_insee'] == code_insee][i].iloc[0] for i in liste_candidat

    infos = {'candidat' : liste_candidat,
            'vote' : donnees}

    df_info = pd.DataFrame(infos)
    data = df_info.to_dict('rows')

    return dash_table.DataTable(
        columns=[{'id':'candidat','name':'Candidat'},{'id':'vote','name':'% des voix'}],
        data= data,
        style_cell= {'background': 'linear-gradient(90deg, red, red 60%, white)',"fontFamily": "Arial", "size": 18, 'textAlign': 'left'},

I have to intervene on my return in the style_cell but I don’t know how, thank you for your help

I think you have to set the style_data_conditional properties of your table. The style_cell properties is for all the cell of the tab, but you want to change the color of a row.

I think you have first to compute the color of the cell and then you set the color using conditional formatting.

df["color"] = df["vote"].apply(my_color(vote))
style_data_conditional = list()
for i, color in enumerate(df["color"]):
        "if": {"row_index": i},
        "backgroundColor": color