Hi @tom-kaufman
With the DataTable
, I couldn’t figure out how to make this work with Boolean columns but I was able to make it work if the column was text:
from dash import Dash, html, dash_table
import pandas as pd
data = {
"ticker": ["AAPL", "MSFT", "AMZN", "GOOGL"],
"company": ["Apple", "Microsoft", "Amazon", "Alphabet"],
"quantity": [75, 40, 100, 50],
"sell": ["True", "False", "True", "False"],
}
df = pd.DataFrame(data)
style_data_conditional=[
{
'if': {
'filter_query': '{sell} = True',
},
'backgroundColor': "#FF4136",
},
]
table = dash_table.DataTable(
columns=[{"name": i, "id": i} for i in df.columns],
data=df.to_dict("records"),
style_data_conditional=style_data_conditional
)
app = Dash(__name__)
app.layout = html.Div(table, style={"margin": 20})
if __name__ == "__main__":
app.run_server(debug=True)
It works with Dash AG Grid though! Here’s an example:
import dash_ag_grid as dag
from dash import Dash, html
import pandas as pd
data = {
"ticker": ["AAPL", "MSFT", "AMZN", "GOOGL"],
"company": ["Apple", "Microsoft", "Amazon", "Alphabet"],
"quantity": [75, 40, 100, 50],
"sell": [True, False, True, False],
}
df = pd.DataFrame(data)
rowStyle = {
"styleConditions": [
{
"condition": "params.data.sell",
"style": {"backgroundColor": "#FF4136"},
},
]
}
grid = dag.AgGrid(
columnDefs=[{"field": i} for i in df.columns],
rowData=df.to_dict("records"),
columnSize="responsiveSizeToFit",
getRowStyle=rowStyle,
)
app = Dash(__name__)
app.layout = html.Div(grid, style={"margin": 20})
if __name__ == "__main__":
app.run_server(debug=True)
For more information about styling rows in the grid see: