Hi there,
I am an R user that is learning Observable. I would like to have a table with some entire rows formatted (e.g., with a background color) based on the values of a single cell. I could not find or did not understand how to set any existing property of the Table widget to fill an entire row with a background color (something similar to formatStyle() in R DT).
I tried changing the values in the array of objects by injecting some HTML, but it did not work. The html code is not rendered. Any help would be very appreciated.
This is the code I used (dataframe penguins)
function changeValueinHtml(value){
const val = htl.html`<div style='background: #fde9d2; float: left; width: 100%; display: block;'>${value}</div>`
return val
}
function createNewArray(arToFormat){
let newArray = [];
arToFormat.map((val)=>{
if (val['culmen_length_mm']>40){
const valNew = {"species": changeValueinHtml(val["species"]),
"culmen_length_mm": changeValueinHtml(val["culmen_length_mm"])}
newArray.push(valNew)
} else {
const valNew = {"species": htl.html`<div>${val["species"]}</div>`,
"culmen_length_mm": htl.html`<div>${val["culmen_length_mm"]}</div>`}
newArray.push(valNew)
}
})
return newArray
}
penguisFormatted = createNewArray(penguins)
Inputs.table(penguisFormatted, {})