Below is the structured dataframe I am working with in R:
Dataframe-
seq count percentage Marking count Percentage batch_no count Percentage
FRD 1 12.50% S1 2 25.00% 6 1 12.50%
FHL 1 12.50% S2 1 12.50% 7 2 25.00%
ABC 2 25.00% S3 1 12.50% 8 2 25.00%
DEF 1 12.50% Hold 2 25.00% 9 1 12.50%
XYZ 1 12.50% NA 1 12.50% NA 1 12.50%
ZZZ 1 12.50% (Blank) 1 12.50% (Blank) 1 12.50%
FRD 1 12.50% - - - - - -
NA 1 12.50% - - - - - -
(Blank) 0 0.00% - - - - - -
Total 8 112.50% - 8 100.00% - 8 100.00%
The number of columns in the dataframe is fixed, but the number of rows can vary depending on certain conditions. The table might have anywhere from 4 to 15 rows.
I want to customize the table by setting the header color to light green with bold font, and the last row should be yellow with bold font. Additionally, I want to highlight rows where the Percentage
of 'Hold' in 'Marking' and the Percentage
of '8' in 'batch_no' are greater than 25%, by marking them as dark red with bold white font.
If possible, I would like to add the suffix '(In Progress)' for 'S3' and '9', respectively, where the font size of '(In Progress)' will be two sizes smaller than the variable name.
The '(In Progress)' text should appear in yellow font with bold styling.
Here is the code snippet I am using:
library(tableHTML)
library(dplyr)
add_font <- function(x) {
x <- gsub('\\(', '\\(<font size="-1">', x)
x <- gsub('\\)', '</font>\\)', x)
return(prettyNum(x, big.mark = ','))
}
Html_Table<-Dataframe %>%
mutate(`Marking` = add_font(`Marking`),
`batch_no` = add_font(`batch_no`)) %>%
tableHTML(rownames = FALSE,
escape = FALSE,
widths = rep(100, 12),
caption = "Dataframe: Test",
theme='scientific') %>%
add_css_caption(css = list(c("font-weight", "border","font-size"),
c("bold", "1px solid black","16px"))) %>
add_css_row(css = list(c("background-color"), c("lightblue")), rows = 0:1)%>
add_css_caption(css = list(c("background-color"), c("lightblue"))) %>
add_css_row(css = list('background-color', '#f2f2f2'),
rows = odd(1:10)) %>
add_css_row(css = list('background-color', '#e6f0ff'),
rows = even(1:10)) %>
add_css_row(css = list(c("background-color","font-weight"), c("yellow", "bold")),
rows = even(2:3)) %>
add_css_row(css = list(c("font-style","font-size"), c("italic","12px")),
rows = 4:8)