First thanks for the great work on streamlit-aggrid to Pablo Fonseca.
I’m trying to highlight minimum and maximum numeric values of a pd.dataframe within streamlit-aggrid.
My problem is that I see no reference to a complete column inside JsCode function(params) {...}
If there is one, Math.max(column)
could be used in jscript for comparison with params.value
but I’m failing here.
My next approach was to create new columns for the dataframe containing min max values
but to get that working I would need to get rid of this temporary columns prior to displaying them:
df = df.copy().reset_index()
for col in df.columns:
max = f"{col}_max"
min = f"{col}_min"
df[max] = df[col].max()
df[min] = df[col].min()
cellstyle_jscode = JsCode("""
function(params) {
var max = params.column.colDef.headerName + '_max';
var min = params.column.colDef.headerName + '_min';
if (params.value == params.data[max]) {
return {
'color': 'black',
'backgroundColor': 'lightblue',
}
}
else if (params.value == params.data[min]) {
return {
'color': 'black',
'backgroundColor': 'yellow',
}
} else {
return {
'color': 'black',
'backgroundColor': 'white'
}
}
};
""")
for column in df:
gb.configure_column(column, cellStyle=cellstyle_jscode)
Below the uggly result
I need to get rid of the date_max, date_min and all other _max, _min columns (see the picture).
Or even better an approach which can calculate maximum and minimum of the column inside
Jscode.
Thanks for any hints