I am writing a Shiny app that has a data table. I am looking to color code rows based on the values of two columns. Even there are values in the 30 Day column that are greater than the Overall column, all values are black. I have tried a for loop as well, but this did not work either. Is there a way to compare two columns in a data table and make a style change based on the results of the comparison?
setDT(a)
a[,group_i := as.Date(DATE) >= Sys.Date()-30]
output$tab<-DT::renderDataTable({
dt<-datatable(a[, .(
"Overall Percent" = round(sum(OPERATION_STATUS == "FAIL") / .N * 100, 2),
"30 Day Percent" = round(sum(OPERATION_STATUS[group_i] == "FAIL") / sum(group_i) * 100, 2)
),
keyby = .("Area" = CRIT_CODE)], rownames = FALSE) %>%
formatStyle("Area", color=ifelse(("Overall Percent" < "30 Day Percent"), "red", "black"), target="row)
return(dt)