Nothing mentioned Styling | Dash for Python Documentation | Plotly
but is it possible to assign rgb color based on the value of a datatable column, e.g. gradient color?
Hi @dqiu, please see the disscussion on the open issue in dash-table or here in the forum.
At the moment you can either use the plotly heatmap (as discussed in the github issue) or conditional formatting (as in the forum post, also see https://dash.plot.ly/datatable/style - search for conditional formatting).
Take the example below, how can I access the cell value when setting ‘color’?
dash_table.DataTable(
data=df.to_dict('records'),
columns=[
{"name": i, "id": i} for i in df.columns
],
style_data_conditional=[{
"if": {"row_index": 4},
"backgroundColor": "#3D9970",
'color': 'white'
}]
)
dash_table.DataTable(
data=df.to_dict('records'),
columns=[
{"name": i, "id": i} for i in df.columns
],
style_data_conditional=([{
"if": {"row_index": 4},
"backgroundColor": "#3D9970",
'color': 'white' if v > 0 else 'black'
} for i, d in enumerate(df.to_dict('records')) for k, v in d.items()])
)
use ‘row_index’: i, ‘column_id’: k if you want to point to a specific cell
use ‘backgroundColor’: rgb(v,v,v) to create “heatmap”
you can filter out values using if
for i, d in enumerate(df.to_dict(‘records’)) for k, v in d.items() if k not in [‘foo’, ‘bar’]
I didn’t try this specific code but something very similar works great for me