, tableHTML .
css , , . 2 , .
library(tableHTML)
col1. , .
get_background_column_css <- function(col1,
a_col = "lightgray",
b_col = "steelblue",
c_col = "lightgreen",
d_col = "indianred",
default = "white") {
background_color_col2 <- ifelse(col1 == "A", a_col,
ifelse(col1 == "B", b_col,
ifelse(col1 == "C", c_col,
ifelse(col1 == "D", d_col, default
))))
css_col2 <- setNames(list(list(c("background-color"),
list(background_color_col2))), "col2")
background_color_col3 <- ifelse(col1 == "B", b_col,
ifelse(col1 == "C", c_col, default))
css_col3 <- setNames(list(list(c("background-color"),
list(background_color_col3))), "col3")
background_color_col4 <- rep("", length(col1))
css_col4 <- setNames(list(list(c("background-color"),
list(background_color_col4))), "col4")
background_color_col5 <- ifelse(col1 == "A", a_col,
ifelse(col1 == "B", b_col,
ifelse(col1 == "C", c_col,
ifelse(col1 == "D", d_col, default
))))
css_col5 <- setNames(list(list(c("background-color"),
list(background_color_col5))), "col5")
list(css_col2, css_col3, css_col4, css_col5)
}
.
get_border_column_css <- function(col1) {
border_col2 <- ifelse(col1 == "D", "1px solid black", "0px")
css_col2 <- setNames(list(list(c("border-right"),
list(border_col2))), "col2")
border_col3 <- ifelse(col1 == "C", "1px solid black", "0px")
css_col3 <- setNames(list(list(c("border-right"),
list(border_col3))), "col3")
border_col4 <- ifelse(col1 == "B", "1px solid black", "0px")
css_col4 <- setNames(list(list(c("border-right"),
list(border_col4))), "col4")
border_col5 <- rep("0px", length(col1))
css_col5 <- setNames(list(list(c("border-right"),
list(border_col5))), "col5")
list(css_col2, css_col3, css_col4, css_col5)
}
, 4 ( ):
test_df <- head(test_df, 4)
1 css- background-color 1 css- border, add_css_conditional_column()
css_background = get_background_column_css(test_df$col1)
css_border = get_border_column_css(test_df$col1)
tableHTML.
tableHTML <- tableHTML(test_df,
rownames = FALSE,
border = 0)
, :
for (i in 1:4) {
tableHTML <- tableHTML %>%
add_css_conditional_column(conditional = "colour_rank",
colour_rank_css = css_background[[i]],
columns = names(test_df)[i + 1])
}
css:
for (i in 1:4) {
tableHTML <- tableHTML %>%
add_css_conditional_column(conditional = "colour_rank",
colour_rank_css = css_border[[i]],
columns = names(test_df)[i + 1])
}
:
tableHTML
