Selectively colouring cells in gt::gt()
This example uses the R package `gt()` to display a data table where individual cells are selectively colored grey, and then a second table where cells are filled with colors from a predefined palette based on a comparison. The code first identifies cells containing "<" characters using `grepl` and applies a uniform grey fill via `tab_style` and `cell_fill`. A more complex workflow melts data frames with `data.table::melt`, merges them with guideline thresholds, and determines which numeric results exceed those thresholds, assigning a color from `RColorBrewer` to each qualifying cell. The `mapply` function iterates over row and column indices to apply the styling individually, producing a table where colored cells highlight values that meet specific criteria. The data is created inline as sample data frames, and the rendering approach relies on the `gt` package's HTML table output.
AI-generated description