| #' HTML table attributes |
| #' |
| #' @description This function provides a set of shortcuts to common HTML table |
| #' formats |
| #' |
| #' @param bootstrap_options A character vector for bootstrap table options. For |
| #' detailed information, please check the package vignette or visit the |
| #' w3schools' \href{https://www.w3schools.com/bootstrap/bootstrap_tables.asp}{Bootstrap Page} |
| #' . Possible options include "bs-table", "striped", "bordered", "hover", |
| #' "condensed" and "responsive". |
| #' @param full_width A `TRUE` or `FALSE` variable controlling whether the HTML |
| #' table should have 100\% width. |
| #' @param float A character string determining whether and how the HTML table |
| #' should float on the page. Values could be "left", "center", "right" |
| #' @param font_size A numeric input for table font size |
| #' |
| #' @export |
| htmlTable_styling <- function(bootstrap_options = "bs-table", |
| full_width = T, |
| float = c("center", "left", "right"), |
| font_size = NULL) { |
| bootstrap_options <- match.arg( |
| bootstrap_options, |
| c("bs-table", "striped", "bordered", "hover", "condensed", "responsive"), |
| several.ok = T |
| ) |
| |
| table_attr_class <- character() |
| if (length(bootstrap_options) == 1 && bootstrap_options == "bs-table") { |
| table_attr_class <- "class='table'" |
| } else { |
| bootstrap_options <- bootstrap_options[bootstrap_options != "bs-table"] |
| bootstrap_options <- paste0("table-", bootstrap_options) |
| table_attr_class <- paste0("class='table ", |
| paste0(bootstrap_options, collapse = " "), "'") |
| } |
| |
| table_attr_style <- c() |
| if (!is.null(font_size)) { |
| table_attr_style <- c(table_attr_style, |
| paste0("font-size: ", font_size, "px;")) |
| } |
| if (!full_width) { |
| table_attr_style <- c(table_attr_style, "width: auto !important;") |
| } |
| |
| float <- match.arg(float) |
| if (float == "center") { |
| table_attr_style <- c(table_attr_style, |
| "margin-left:auto; margin-right:auto;") |
| } |
| if (float == "right") { |
| table_attr_style <- c(table_attr_style, |
| "float: right;") |
| } |
| if (length(table_attr_style) != 0) { |
| table_attr_style <- paste0("style = '", |
| paste0(table_attr_style, collapse = " "), "'") |
| } |
| return(paste(table_attr_class, table_attr_style)) |
| } |