Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 1 | #' @export |
Hao Zhu | b9da01c | 2018-01-14 21:01:57 -0500 | [diff] [blame] | 2 | print.kableExtra <- function(x, ...) { |
Hao Zhu | d12f483 | 2020-08-09 15:52:37 -0400 | [diff] [blame] | 3 | view_html <- getOption("kableExtra_view_html", TRUE) |
| 4 | if (view_html) { |
| 5 | dep <- list( |
| 6 | rmarkdown::html_dependency_jquery(), |
| 7 | rmarkdown::html_dependency_bootstrap(theme = "cosmo"), |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 8 | html_dependency_kePrint(), |
| 9 | html_dependency_lightable() |
Hao Zhu | d12f483 | 2020-08-09 15:52:37 -0400 | [diff] [blame] | 10 | ) |
| 11 | html_kable <- htmltools::browsable( |
| 12 | htmltools::HTML( |
| 13 | as.character(x), |
| 14 | '<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [["$","$"], ["\\(","\\)"]]}})</script><script async src="https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>' |
Hao Zhu | 47b1343 | 2020-08-03 16:20:51 -0400 | [diff] [blame] | 15 | ) |
Hao Zhu | d12f483 | 2020-08-09 15:52:37 -0400 | [diff] [blame] | 16 | ) |
| 17 | htmlDependencies(html_kable) <- dep |
| 18 | class(html_kable) <- "shiny.tag.list" |
| 19 | print(html_kable) |
| 20 | } else { |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 21 | cat(as.character(x)) |
Hao Zhu | d12f483 | 2020-08-09 15:52:37 -0400 | [diff] [blame] | 22 | } |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 23 | } |
| 24 | |
Hao Zhu | 6107f37 | 2018-05-21 00:23:26 -0400 | [diff] [blame] | 25 | #' HTML dependency for js script to enable bootstrap tooltip and popup message |
| 26 | #' |
Hao Zhu | e5b9bff | 2018-05-20 17:40:03 -0400 | [diff] [blame] | 27 | #' @export |
Hao Zhu | 8a69ad1 | 2018-01-10 18:01:41 -0500 | [diff] [blame] | 28 | html_dependency_kePrint <- function() { |
| 29 | htmlDependency(name = "kePrint", |
| 30 | version = "0.0.1", |
Hao Zhu | 7cb0e37 | 2018-01-10 18:29:30 -0500 | [diff] [blame] | 31 | src = system.file("kePrint-0.0.1", |
Hao Zhu | 8a69ad1 | 2018-01-10 18:01:41 -0500 | [diff] [blame] | 32 | package = "kableExtra"), |
| 33 | script = "kePrint.js") |
| 34 | } |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 35 | |
Hao Zhu | 6107f37 | 2018-05-21 00:23:26 -0400 | [diff] [blame] | 36 | #' HTML dependency for Twitter bootstrap (table only) |
| 37 | #' |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 38 | #' @export |
Hao Zhu | e5b9bff | 2018-05-20 17:40:03 -0400 | [diff] [blame] | 39 | html_dependency_bsTable <- function() { |
| 40 | htmlDependency(name = "bsTable", |
| 41 | version = "3.3.7", |
| 42 | src = system.file("bootstrapTable-3.3.7", |
| 43 | package = "kableExtra"), |
Hao Zhu | 4a888b3 | 2020-08-11 15:48:23 -0400 | [diff] [blame] | 44 | stylesheet = "bootstrapTable.min.css", |
| 45 | script = "bootstrapTable.js") |
Hao Zhu | e5b9bff | 2018-05-20 17:40:03 -0400 | [diff] [blame] | 46 | } |
| 47 | |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 48 | #' HTML dependency for lightable |
| 49 | #' |
| 50 | #' @export |
| 51 | html_dependency_lightable <- function() { |
| 52 | htmlDependency(name = "lightable", |
| 53 | version = "0.0.1", |
| 54 | src = system.file("lightable-0.0.1", |
| 55 | package = "kableExtra"), |
| 56 | stylesheet = "lightable.css") |
| 57 | } |
| 58 | |
Hao Zhu | e5b9bff | 2018-05-20 17:40:03 -0400 | [diff] [blame] | 59 | #' @export |
Hao Zhu | c830679 | 2018-01-11 12:34:35 -0500 | [diff] [blame] | 60 | knit_print.kableExtra <- function(x, ...) { |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 61 | x <- paste0(x, "\n\n") |
Hao Zhu | c145088 | 2018-10-03 17:56:26 -0400 | [diff] [blame] | 62 | kp_dependency <- getOption("kableExtra.knit_print.dependency", |
| 63 | default = TRUE) |
| 64 | if (kp_dependency) { |
| 65 | meta_list <- list(html_dependency_kePrint()) |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 66 | meta_list[[2]] <- html_dependency_lightable() |
Hao Zhu | c145088 | 2018-10-03 17:56:26 -0400 | [diff] [blame] | 67 | bs <- getOption("kableExtra.html.bsTable", default = FALSE) |
| 68 | if (bs) { |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 69 | meta_list[[3]] <- html_dependency_bsTable() |
Hao Zhu | c145088 | 2018-10-03 17:56:26 -0400 | [diff] [blame] | 70 | } |
| 71 | } else { |
| 72 | meta_list <- NULL |
Hao Zhu | e5b9bff | 2018-05-20 17:40:03 -0400 | [diff] [blame] | 73 | } |
| 74 | asis_output(x, meta = meta_list) |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
Hao Zhu | 9410a27 | 2020-08-03 01:11:47 -0400 | [diff] [blame] | 80 | |
| 81 | |