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"), |
| 8 | html_dependency_kePrint() |
| 9 | ) |
| 10 | html_kable <- htmltools::browsable( |
| 11 | htmltools::HTML( |
| 12 | as.character(x), |
| 13 | '<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] | 14 | ) |
Hao Zhu | d12f483 | 2020-08-09 15:52:37 -0400 | [diff] [blame^] | 15 | ) |
| 16 | htmlDependencies(html_kable) <- dep |
| 17 | class(html_kable) <- "shiny.tag.list" |
| 18 | print(html_kable) |
| 19 | } else { |
| 20 | print(as.character(x)) |
| 21 | } |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 22 | } |
| 23 | |
Hao Zhu | 6107f37 | 2018-05-21 00:23:26 -0400 | [diff] [blame] | 24 | #' HTML dependency for js script to enable bootstrap tooltip and popup message |
| 25 | #' |
Hao Zhu | e5b9bff | 2018-05-20 17:40:03 -0400 | [diff] [blame] | 26 | #' @export |
Hao Zhu | 8a69ad1 | 2018-01-10 18:01:41 -0500 | [diff] [blame] | 27 | html_dependency_kePrint <- function() { |
| 28 | htmlDependency(name = "kePrint", |
| 29 | version = "0.0.1", |
Hao Zhu | 7cb0e37 | 2018-01-10 18:29:30 -0500 | [diff] [blame] | 30 | src = system.file("kePrint-0.0.1", |
Hao Zhu | 8a69ad1 | 2018-01-10 18:01:41 -0500 | [diff] [blame] | 31 | package = "kableExtra"), |
| 32 | script = "kePrint.js") |
| 33 | } |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 34 | |
Hao Zhu | 6107f37 | 2018-05-21 00:23:26 -0400 | [diff] [blame] | 35 | #' HTML dependency for Twitter bootstrap (table only) |
| 36 | #' |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 37 | #' @export |
Hao Zhu | e5b9bff | 2018-05-20 17:40:03 -0400 | [diff] [blame] | 38 | html_dependency_bsTable <- function() { |
| 39 | htmlDependency(name = "bsTable", |
| 40 | version = "3.3.7", |
| 41 | src = system.file("bootstrapTable-3.3.7", |
| 42 | package = "kableExtra"), |
| 43 | stylesheet = "bootstrapTable.min.css") |
| 44 | } |
| 45 | |
| 46 | #' @export |
Hao Zhu | c830679 | 2018-01-11 12:34:35 -0500 | [diff] [blame] | 47 | knit_print.kableExtra <- function(x, ...) { |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 48 | x <- paste0(x, "\n\n") |
Hao Zhu | c145088 | 2018-10-03 17:56:26 -0400 | [diff] [blame] | 49 | kp_dependency <- getOption("kableExtra.knit_print.dependency", |
| 50 | default = TRUE) |
| 51 | if (kp_dependency) { |
| 52 | meta_list <- list(html_dependency_kePrint()) |
| 53 | bs <- getOption("kableExtra.html.bsTable", default = FALSE) |
| 54 | if (bs) { |
| 55 | meta_list[[2]] <- html_dependency_bsTable() |
| 56 | } |
| 57 | } else { |
| 58 | meta_list <- NULL |
Hao Zhu | e5b9bff | 2018-05-20 17:40:03 -0400 | [diff] [blame] | 59 | } |
| 60 | asis_output(x, meta = meta_list) |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
Hao Zhu | 9410a27 | 2020-08-03 01:11:47 -0400 | [diff] [blame] | 66 | |
| 67 | |