Adding lightable theme
diff --git a/NAMESPACE b/NAMESPACE
index 7c27526..bca3902 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -20,10 +20,14 @@
export(group_rows)
export(html_dependency_bsTable)
export(html_dependency_kePrint)
+export(html_dependency_lightable)
export(kable)
export(kableExtra_latex_packages)
export(kable_as_image)
export(kable_as_xml)
+export(kable_classic)
+export(kable_material)
+export(kable_minimal)
export(kable_styling)
export(landscape)
export(linebreak)
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
diff --git a/inst/NEWS.md b/inst/NEWS.md
index 6235eb8..b7de0c8 100644
--- a/inst/NEWS.md
+++ b/inst/NEWS.md
@@ -28,10 +28,14 @@
* Fixed a bug when using UTF-8 on non-UTF-8 system. (#440, thanks @jokorn)
+* Added a global option to control whether to preview HTML tables in RStudio
+viewer. If you want to disable the default behavior, try to set
+`options(kableExtra_view_html = F)`. (#455)
-kableExtra ]
-1.1.0
+
+
+kableExtra 1.1.0
--------------------------------------------------------------------------------
# Major Changes
diff --git a/inst/lightable-0.0.1/lightable.css b/inst/lightable-0.0.1/lightable.css
new file mode 100644
index 0000000..4c45eb2
--- /dev/null
+++ b/inst/lightable-0.0.1/lightable.css
@@ -0,0 +1,81 @@
+/*!
+ * lightable v0.0.1
+ * Copyright 2020 Hao Zhu
+ * Licensed under MIT (https://github.com/haozhu233/kableExtra/blob/master/LICENSE)
+ */
+
+.lightable-minimal {
+ border-collapse: separate;
+ border-spacing: 16px 1px;
+ width: 100%;
+}
+
+.lightable-minimal thead tr th {
+ border-bottom: 2px solid black;
+ empty-cells: hide;
+}
+
+.lightable-minimal tbody tr:first-child td {
+ padding-top: 0.5em;
+}
+
+.lightable-minimal.lightable-hover tr:hover {
+ background-color: #f5f5f5;
+}
+
+.lightable-minimal.lightable-striped tr:nth-child(even) {
+ background-color: #f5f5f5;
+}
+
+.lightable-classic {
+ border-top: 2px solid #111111;
+ border-bottom: 2px solid #111111;
+ width: 100%;
+}
+
+.lightable-classic thead tr:last-child th {
+ border-bottom: 1px solid #111111;
+}
+
+.lightable-classic.lightable-hover tr:hover {
+ background-color: #f5f5f5;
+}
+
+.lightable-classic.lightable-striped tr:nth-child(even) {
+ background-color: #f5f5f5;
+}
+
+.lightable-material {
+ min-width: 100%;
+ white-space: nowrap;
+ table-layout: fixed;
+ font-family: Roboto, sans-serif;
+ border: 1px solid #EEE;
+ border-collapse: collapse;
+}
+
+.lightable-material th {
+ padding: 0.8em;
+ background-color: #f5f5f5;
+}
+
+.lightable-material td {
+ padding: 0.8em;
+ border-top: 1px solid #eeeeee;
+}
+
+.lightable-material.lightable-hover tr:hover {
+ background-color: #f5f5f5;
+}
+
+.lightable-material.lightable-striped tr:nth-child(even) {
+ background-color: #f5f5f5;
+}
+
+.lightable-material.lightable-striped td {
+ border: 0px;
+}
+
+.lightable-material.lightable-striped thead tr:last-child th {
+ border-bottom: 1px solid #ddd;
+}
diff --git a/man/add_header_above.Rd b/man/add_header_above.Rd
index 2f0d133..99e6931 100644
--- a/man/add_header_above.Rd
+++ b/man/add_header_above.Rd
@@ -33,7 +33,11 @@
example, \code{c(" " = 1, "title" = 2)} can be used to create a new header row
for a 3-column table with "title" spanning across column 2 and 3. For
convenience, when \code{colspan} equals to 1, users can drop the \verb{ = 1} part.
-As a result, \code{c(" ", "title" = 2)} is the same as \code{c(" " = 1, "title" = 2)}.}
+As a result, \code{c(" ", "title" = 2)} is the same as \code{c(" " = 1, "title" = 2)}.
+Alternatively, a data frame with two columns can be provided: The first
+column should contain the header names (character vector) and the second
+column should contain the colspan (numeric vector). This input can be used
+if there are problems with unicode characters in the headers.}
\item{bold}{A T/F value to control whether the text should be bolded.}
diff --git a/man/html_dependency_lightable.Rd b/man/html_dependency_lightable.Rd
new file mode 100644
index 0000000..8894860
--- /dev/null
+++ b/man/html_dependency_lightable.Rd
@@ -0,0 +1,11 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/print.R
+\name{html_dependency_lightable}
+\alias{html_dependency_lightable}
+\title{HTML dependency for lightable}
+\usage{
+html_dependency_lightable()
+}
+\description{
+HTML dependency for lightable
+}
diff --git a/man/kable_classic.Rd b/man/kable_classic.Rd
new file mode 100644
index 0000000..b453748
--- /dev/null
+++ b/man/kable_classic.Rd
@@ -0,0 +1,30 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/light_themes.R
+\name{kable_classic}
+\alias{kable_classic}
+\alias{kable_minimal}
+\alias{kable_material}
+\title{Alternative HTML themes}
+\usage{
+kable_classic(kable_input, striped = FALSE, hover = FALSE, ...)
+
+kable_minimal(kable_input, striped = FALSE, hover = FALSE, ...)
+
+kable_material(kable_input, striped = FALSE, hover = FALSE, ...)
+}
+\arguments{
+\item{kable_input}{A HTML kable object.}
+
+\item{striped}{T/F for adding striped rows.}
+
+\item{hover}{T/F for adding hover effects.}
+
+\item{...}{Everything else you need to specify in \code{kable_styling}.}
+}
+\description{
+kableExtra uses the built-in bootstrap themes by default in
+\code{kable_styling()}. Alternatively, you can use a customized table themes for
+your table. This \code{lightable} table style sheet comes with three formats,
+namely \code{lightable-minimal}, \code{lightable-classic} and \code{lightable-material} with
+\code{hover} and \code{striped} options.
+}
diff --git a/man/kable_styling.Rd b/man/kable_styling.Rd
index f21be79..49c17c8 100644
--- a/man/kable_styling.Rd
+++ b/man/kable_styling.Rd
@@ -20,7 +20,8 @@
latex_table_env = NULL,
protect_latex = TRUE,
table.envir = "table",
- fixed_thead = FALSE
+ fixed_thead = FALSE,
+ lightable_class = NULL
)
}
\arguments{
@@ -30,7 +31,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 \code{basic}, \code{striped},
-\code{bordered}, \code{hover}, \code{condensed} and \code{responsive}.}
+\code{bordered}, \code{hover}, \code{condensed}, \code{responsive} and \code{none}.}
\item{latex_options}{A character vector for LaTeX table options. Please see
package vignette for more information. Possible options include
@@ -94,6 +95,10 @@
\item{fixed_thead}{HTML table option so table header row is fixed at top.
Values can be either T/F or \code{list(enabled = T/F, background = "anycolor")}.}
+
+\item{lightable_class}{Options to use the in-house lightable themes.
+Choices include \code{lightable-minimal}, \code{lightable-classic},
+\code{lightable-material}, \code{lightable-striped} and \code{lightable-hover}.}
}
\description{
This function provides a cleaner approach to modify the style