I think you can, through the style_data_conditional
parameter of DataTable
.
I just tried it with the following simple code (adapted from the style page you reference). I made the table editable, and added a condition to change the color of the cell if it is in column a
and its value is greater than 3. It worked.
Alternatively, you might have a callback function that modifies the cell values through the data
property, and once you have the conditional formatting in place colors, fonts, etc. should change dynamically.
import dash
import dash_html_components as html
import pandas as pd
from dash_table import DataTable
df = pd.DataFrame({
'a': [1, 2, 3, 4],
'b': [5, 6, 7, 8],
'c': [10, 20, 30, 40]
})
app = dash.Dash(__name__)
app.layout = html.Div([
DataTable(id='table',
editable=True,
data=df.to_dict('records'),
columns=[{'id': c, 'name': c} for c in df.columns],
style_data_conditional=[
{
'if': {
'column_id': 'a',
'filter_query': '{a} gt 3'
},
'backgroundColor': '#3D9970',
'color': 'white',
},
])
])
if __name__ == '__main__':
app.run_server(debug=True)
Hope this works for you.