'Highlight cell color with multiple conditions
I have one dataframe (assume df) where I want to highlight cell color with following condition.
If the value of column B is greater than 1 and the value of column D is greater than 5 then only I want to highlight cell color in column D only with green.
I don't want it to highlight in column B.
Please suggest
Solution 1:[1]
Bokeh 2.x introduced a more rigorous "ndarray" type into BokehJS. It is not widely documented because it is not something the vast majority of users ever have to think or know about. The following callback code seems to work for me. (Note: I had to reduce the image size or set det4 to 5*np.random.random((N, M))-0.5 to actually be able to really see the changes visibly)
const {Float64NDArray} = Bokeh.require("core/util/ndarray")
const d1 = source.data['det1'][0];
const d2 = source.data['det2'][0];
const d3 = source.data['det3'][0];
const d4 = source.data['det4'][0];
const d = source.data['image'];
const sum = new Array();
function sumArrays(...arrays) {
const n = arrays.reduce((max, xs) => Math.max(max, xs.length), 0);
const result = Float64Array.from({ length: n });
return result.map((_, i) => arrays.map(xs => xs[i] || 0).reduce((sum, x) => sum + x, 0));
}
var f = cb_obj.active;
if (f.indexOf(0) > -1) {
sum.push(d1);
}
if (f.indexOf(1) > -1) {
sum.push(d2);
}
if (f.indexOf(2) > -1) {
sum.push(d3);
}
if (f.indexOf(3) > -1) {
sum.push(d4);
}
// here is the important change
d[0] = new Float64NDArray(sumArrays(...sum), sum[0].shape);
source.change.emit();
A few other notes for you, regarding the upcoming Bokeh 3.0:
- The old
figure/Figuredichotomy is removed. Onlyfigurewill exsist in Bokeh 3.0 (and it's mostly all we have ever documented anywhere for a long time) - Deprecated
plot_widthandplot_heightare removed, just usewidthandheightthe same as all other layout-ables.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | bigreddot |
