I have managed to color cells but I also want to draw a line between the cells 3 and 3 and 8 and 9. How do I do that?
df <- data.frame(a=c(4,3,9,9),b=c(5,3,8,8))
## indices defining where the styles go
where <- rbind(c(2,1),c(2,2))
style <- rep(('background-color: orange'),2)
css.cell <- matrix('', nrow(df), ncol(df))
css.cell[where] <- style
library(htmlTable)
htmlTable(df, css.cell = css.cell)
I want it like:
CodePudding user response:
Use border-bottom
:
style <- rep(('background-color: orange; border-bottom: 2px solid;'), 2)
EDIT
For your other question:
df <- data.frame(a=c(4,3,9,9),b=c(5,3,8,8),c=c(5,6,7,8))
## indices defining where the styles go
where1 <- rbind(c(2,1),c(2,2))
style1 <- rep(('background-color: orange; border-bottom: 2px solid;'), 2)
where2 <- rbind(c(2,3))
style2 <- "border-bottom: 2px solid;"
css.cell <- matrix('', nrow(df), ncol(df))
css.cell[where1] <- style1
css.cell[where2] <- style2
library(htmlTable)
htmlTable(df, css.cell = css.cell)
CodePudding user response:
I realize I want to do another step, the coloring and the lining should be separate, how to achieve it? Thanks!
df <- data.frame(a=c(4,3,9,9),b=c(5,3,8,8),c=c(5,6,7,8))
## indices defining where the styles go
where1 <- rbind(c(2,1),c(2,2))
style1 <- rep(('background-color: orange'), 2)
css.cell <- matrix('', nrow(df), ncol(df))
css.cell[where1] <- style1
library(htmlTable)
htmlTable(df, css.cell = css.cell)
This is the wanted output: