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 | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 3 | html_header <- htmltools::tags$head( |
| 4 | rmarkdown::html_dependency_jquery(), |
Hao Zhu | 8a69ad1 | 2018-01-10 18:01:41 -0500 | [diff] [blame] | 5 | rmarkdown::html_dependency_bootstrap(theme = "simplex"), |
| 6 | html_dependency_kePrint() |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 7 | ) |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 8 | html_table <- htmltools::HTML(as.character(x)) |
Hao Zhu | 8c8ac8b | 2018-01-23 23:45:13 -0500 | [diff] [blame] | 9 | html_result <- htmltools::tagList(html_header, html_table) |
Hao Zhu | 5776154 | 2018-03-26 16:32:56 -0400 | [diff] [blame] | 10 | if (interactive() & rstudioapi::isAvailable()) { |
Hao Zhu | 5b71b2d | 2018-03-26 16:31:09 -0400 | [diff] [blame] | 11 | htmltools::html_print(html_result, viewer = rstudioapi::viewer) |
| 12 | } |
Hao Zhu | 76762d8 | 2018-07-25 20:56:52 -0400 | [diff] [blame] | 13 | # print(html_result) |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 14 | } |
| 15 | |
Hao Zhu | 6107f37 | 2018-05-21 00:23:26 -0400 | [diff] [blame] | 16 | #' HTML dependency for js script to enable bootstrap tooltip and popup message |
| 17 | #' |
Hao Zhu | e5b9bff | 2018-05-20 17:40:03 -0400 | [diff] [blame] | 18 | #' @export |
Hao Zhu | 8a69ad1 | 2018-01-10 18:01:41 -0500 | [diff] [blame] | 19 | html_dependency_kePrint <- function() { |
| 20 | htmlDependency(name = "kePrint", |
| 21 | version = "0.0.1", |
Hao Zhu | 7cb0e37 | 2018-01-10 18:29:30 -0500 | [diff] [blame] | 22 | src = system.file("kePrint-0.0.1", |
Hao Zhu | 8a69ad1 | 2018-01-10 18:01:41 -0500 | [diff] [blame] | 23 | package = "kableExtra"), |
| 24 | script = "kePrint.js") |
| 25 | } |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 26 | |
Hao Zhu | 6107f37 | 2018-05-21 00:23:26 -0400 | [diff] [blame] | 27 | #' HTML dependency for Twitter bootstrap (table only) |
| 28 | #' |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 29 | #' @export |
Hao Zhu | e5b9bff | 2018-05-20 17:40:03 -0400 | [diff] [blame] | 30 | html_dependency_bsTable <- function() { |
| 31 | htmlDependency(name = "bsTable", |
| 32 | version = "3.3.7", |
| 33 | src = system.file("bootstrapTable-3.3.7", |
| 34 | package = "kableExtra"), |
| 35 | stylesheet = "bootstrapTable.min.css") |
| 36 | } |
| 37 | |
| 38 | #' @export |
Hao Zhu | c830679 | 2018-01-11 12:34:35 -0500 | [diff] [blame] | 39 | knit_print.kableExtra <- function(x, ...) { |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 40 | x <- paste0(x, "\n\n") |
Hao Zhu | c145088 | 2018-10-03 17:56:26 -0400 | [diff] [blame] | 41 | kp_dependency <- getOption("kableExtra.knit_print.dependency", |
| 42 | default = TRUE) |
| 43 | if (kp_dependency) { |
| 44 | meta_list <- list(html_dependency_kePrint()) |
| 45 | bs <- getOption("kableExtra.html.bsTable", default = FALSE) |
| 46 | if (bs) { |
| 47 | meta_list[[2]] <- html_dependency_bsTable() |
| 48 | } |
| 49 | } else { |
| 50 | meta_list <- NULL |
Hao Zhu | e5b9bff | 2018-05-20 17:40:03 -0400 | [diff] [blame] | 51 | } |
| 52 | asis_output(x, meta = meta_list) |
Hao Zhu | eaef431 | 2018-01-10 17:05:23 -0500 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | |
| 56 | |
| 57 | |