formatting - Conditionally coloring a cell in htmlTable for R -
i'm using excellent htmltable
package printing results in rmarkdown. 1 of tables shows values between 0 1. have generated vector of 100 colors interpolated between white (#ffffff) , red (#ff5555) i'd match each cell's background depending on it's value.
the logical part clear me (multiply cell's value 100, round , extract color corresponding index of color vector).
what i'm not sure is, having matched color each cell, how make htmltable
paint it?
thanks!
i think can using rgb colors like:
paste0("background-color:rgb(255, ",value*255," , ",value*255 ," )"
where value cell value 0 1
example( 0 red,1 white)
df = as.data.frame(matrix(round(runif(15, 0, 1), 1),ncol = 3 )) htmltable::htmltable(df,css.cell=apply(df,c(1,2),function(i)paste0("background-color:rgb(255, ",round(i*255,0)," , ",round(i*255,0) ," )")))
Comments
Post a Comment