Skip to contents

Create reactable table from matrix data

Usage

show_reactable(totab, colfun, nrows = 10, txtsz = 3)

Arguments

totab

A data frame in wide format of summarized results

colfun

Function specifying how colors are treated in cell background

nrows

numeric specifying number of rows in the table

txtsz

numeric indicating text size in the cells, use txtsz = NULL to suppress

Value

A reactable table

Details

This function is used internally within show_matrix and show_wqmatrix

Examples

data(targets)
data(epcdata)

library(tidyr)
library(dplyr)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union

# data
totab <- anlz_avedat(epcdata) %>%
  .$ann %>%
  filter(var %in% 'mean_chla') %>%
  left_join(targets, by = 'bay_segment') %>%
  select(bay_segment, yr, val, chla_thresh) %>%
  mutate(
    bay_segment = factor(bay_segment, levels = c('OTB', 'HB', 'MTB', 'LTB')),
     outcome = case_when(
      val < chla_thresh ~ 'green',
      val >= chla_thresh ~ 'red'
    )
  ) %>%
  select(bay_segment, yr, outcome) %>%
  spread(bay_segment, outcome)

# color function
colfun <- function(x){

  out <- case_when(
    x == 'red' ~ '#FF3333',
    x == 'green' ~ '#33FF3B'
  )

  return(out)

}

show_reactable(totab, colfun)