Adding lightable theme
diff --git a/R/kable_styling.R b/R/kable_styling.R
index 7e4c5e7..f8aacd0 100644
--- a/R/kable_styling.R
+++ b/R/kable_styling.R
@@ -10,7 +10,7 @@
#' Please see package vignette or visit the w3schools'
#' \href{https://www.w3schools.com/bootstrap/bootstrap_tables.asp}{Bootstrap Page}
#' for more information. Possible options include `basic`, `striped`,
-#' `bordered`, `hover`, `condensed` and `responsive`.
+#' `bordered`, `hover`, `condensed`, `responsive` and `none`.
#' @param latex_options A character vector for LaTeX table options. Please see
#' package vignette for more information. Possible options include
#' `basic`, `striped`, `hold_position`, `HOLD_position`, `scale_down` & `repeat_header`.
@@ -60,6 +60,9 @@
#' on your need.
#' @param fixed_thead HTML table option so table header row is fixed at top.
#' Values can be either T/F or `list(enabled = T/F, background = "anycolor")`.
+#' @param lightable_class Options to use the in-house lightable themes.
+#' Choices include `lightable-minimal`, `lightable-classic`,
+#' `lightable-material`, `lightable-striped` and `lightable-hover`.
#'
#' @details For LaTeX, if you use other than English environment
#' - all tables are converted to 'UTF-8'. If you use, for example, Hungarian
@@ -94,7 +97,8 @@
latex_table_env = NULL,
protect_latex = TRUE,
table.envir = "table",
- fixed_thead = FALSE) {
+ fixed_thead = FALSE,
+ lightable_class = NULL) {
if (length(bootstrap_options) == 1 && bootstrap_options == "basic") {
bootstrap_options <- getOption("kable_styling_bootstrap_options", "basic")
@@ -129,7 +133,8 @@
position = position,
font_size = font_size,
protect_latex = protect_latex,
- fixed_thead = fixed_thead))
+ fixed_thead = fixed_thead,
+ lightable_class = lightable_class))
}
if (kable_format == "latex") {
if (is.null(full_width)) {
@@ -187,7 +192,8 @@
"float_left", "float_right"),
font_size = NULL,
protect_latex = TRUE,
- fixed_thead = FALSE) {
+ fixed_thead = FALSE,
+ lightable_class = NULL) {
if (protect_latex) {
kable_input <- extract_latex_from_kable(kable_input)
}
@@ -197,7 +203,8 @@
# Modify class
bootstrap_options <- match.arg(
bootstrap_options,
- c("basic", "striped", "bordered", "hover", "condensed", "responsive"),
+ c("basic", "striped", "bordered", "hover", "condensed", "responsive",
+ "none"),
several.ok = T
)
@@ -205,15 +212,24 @@
if (xml_has_attr(kable_xml, "class")) {
kable_xml_class <- xml_attr(kable_xml, "class")
}
- if (length(bootstrap_options) == 1 && bootstrap_options == "basic") {
- bootstrap_options <- "table"
- } else {
- bootstrap_options <- bootstrap_options[bootstrap_options != "basic"]
- bootstrap_options <- paste0("table-", bootstrap_options)
- bootstrap_options <- c("table", bootstrap_options)
+
+ if (!is.null(lightable_class)) {
+ bootstrap_options <- "none"
+ xml_attr(kable_xml, "class") <- paste(kable_xml_class, lightable_class)
}
- xml_attr(kable_xml, "class") <- paste(c(kable_xml_class, bootstrap_options),
- collapse = " ")
+
+ if (length(bootstrap_options) == 1 && bootstrap_options == "none") {
+ }else {
+ if (length(bootstrap_options) == 1 && bootstrap_options == "basic") {
+ bootstrap_options <- "table"
+ } else {
+ bootstrap_options <- bootstrap_options[bootstrap_options != "basic"]
+ bootstrap_options <- paste0("table-", bootstrap_options)
+ bootstrap_options <- c("table", bootstrap_options)
+ }
+ xml_attr(kable_xml, "class") <- paste(c(kable_xml_class, bootstrap_options),
+ collapse = " ")
+ }
# Modify style
kable_xml_style <- NULL
diff --git a/R/light_themes.R b/R/light_themes.R
new file mode 100644
index 0000000..f1ec579
--- /dev/null
+++ b/R/light_themes.R
@@ -0,0 +1,53 @@
+#' Alternative HTML themes
+#'
+#' @description kableExtra uses the built-in bootstrap themes by default in
+#' `kable_styling()`. Alternatively, you can use a customized table themes for
+#' your table. This `lightable` table style sheet comes with three formats,
+#' namely `lightable-minimal`, `lightable-classic` and `lightable-material` with
+#' `hover` and `striped` options.
+#'
+#' @param kable_input A HTML kable object.
+#' @param striped T/F for adding striped rows.
+#' @param hover T/F for adding hover effects.
+#' @param ... Everything else you need to specify in `kable_styling`.
+#'
+#' @export
+kable_classic <- function(kable_input, striped = FALSE,
+ hover = FALSE, ...) {
+ light_class <- "lightable-classic"
+ if (striped) {
+ light_class <- paste(light_class, "lightable-striped")
+ }
+ if (hover) {
+ light_class <- paste(light_class, "lightable-hover")
+ }
+ kable_styling(kable_input, "none", lightable_class = light_class, ...)
+}
+
+#' @rdname kable_classic
+#' @export
+kable_minimal <- function(kable_input, striped = FALSE,
+ hover = FALSE, ...) {
+ light_class <- "lightable-minimal"
+ if (striped) {
+ light_class <- paste(light_class, "lightable-striped")
+ }
+ if (hover) {
+ light_class <- paste(light_class, "lightable-hover")
+ }
+ kable_styling(kable_input, "none", lightable_class = light_class, ...)
+}
+
+#' @rdname kable_classic
+#' @export
+kable_material <- function(kable_input, striped = FALSE,
+ hover = FALSE, ...) {
+ light_class <- "lightable-material"
+ if (striped) {
+ light_class <- paste(light_class, "lightable-striped")
+ }
+ if (hover) {
+ light_class <- paste(light_class, "lightable-hover")
+ }
+ kable_styling(kable_input, "none", lightable_class = light_class, ...)
+}
diff --git a/R/print.R b/R/print.R
index 04e55c1..6d1c534 100644
--- a/R/print.R
+++ b/R/print.R
@@ -5,7 +5,8 @@
dep <- list(
rmarkdown::html_dependency_jquery(),
rmarkdown::html_dependency_bootstrap(theme = "cosmo"),
- html_dependency_kePrint()
+ html_dependency_kePrint(),
+ html_dependency_lightable()
)
html_kable <- htmltools::browsable(
htmltools::HTML(
@@ -17,7 +18,7 @@
class(html_kable) <- "shiny.tag.list"
print(html_kable)
} else {
- print(as.character(x))
+ cat(as.character(x))
}
}
@@ -43,6 +44,17 @@
stylesheet = "bootstrapTable.min.css")
}
+#' HTML dependency for lightable
+#'
+#' @export
+html_dependency_lightable <- function() {
+ htmlDependency(name = "lightable",
+ version = "0.0.1",
+ src = system.file("lightable-0.0.1",
+ package = "kableExtra"),
+ stylesheet = "lightable.css")
+}
+
#' @export
knit_print.kableExtra <- function(x, ...) {
x <- paste0(x, "\n\n")
@@ -50,9 +62,10 @@
default = TRUE)
if (kp_dependency) {
meta_list <- list(html_dependency_kePrint())
+ meta_list[[2]] <- html_dependency_lightable()
bs <- getOption("kableExtra.html.bsTable", default = FALSE)
if (bs) {
- meta_list[[2]] <- html_dependency_bsTable()
+ meta_list[[3]] <- html_dependency_bsTable()
}
} else {
meta_list <- NULL