Hao Zhu | 73cf373 | 2018-05-11 17:50:05 -0400 | [diff] [blame] | 1 | #' Save kable to files |
| 2 | #' |
| 3 | #' @param x A piece of HTML code for tables, usually generated by kable and |
| 4 | #' kableExtra |
| 5 | #' @param file save to files |
| 6 | #' @param bs_theme Which Bootstrap theme to use |
| 7 | #' @param self_contained Will the files be self-contained? |
| 8 | #' |
| 9 | #' @export |
| 10 | save_kable <- function(x, file, |
| 11 | bs_theme = "simplex", self_contained = TRUE) { |
| 12 | html_header <- htmltools::tags$head( |
| 13 | rmarkdown::html_dependency_jquery(), |
| 14 | rmarkdown::html_dependency_bootstrap(theme = bs_theme), |
| 15 | html_dependency_kePrint() |
| 16 | ) |
| 17 | html_table <- htmltools::HTML(as.character(x)) |
| 18 | html_result <- htmltools::tagList(html_header, html_table) |
| 19 | htmltools::save_html(html_result, file = file) |
| 20 | if (self_contained) { |
| 21 | rmarkdown::pandoc_self_contained_html(file, file) |
| 22 | unlink("lib", recursive = TRUE) |
| 23 | } |
| 24 | } |