Save input in a self-contained .html file via R markdown.
save_html(x, path, css = NULL)(gtsummary/gt_tbl/flextable/ggplot/grob/list)
object of class 'gtsummary', 'gt_tbl' (gt table), 'flextable', 'ggplot',
'grob', or a list of these objects.
(path)
path to save file to, e.g. "rendered_table.html".
(string)
optional CSS style block to embed in the HTML output. Default is NULL
(no custom CSS). Example: "body { font-family: Arial; font-size: 12px; }".
(invisibly) a string corresponding to the content of the intermediate
.rmd file that is rendered as .html.
# create table
tbl <-
cards::ADAE[1:150, ] |>
gtsummary::tbl_hierarchical(
variables = c(AESOC, AETERM),
by = TRTA,
denominator = cards::ADSL,
id = USUBJID,
)
# rendering to html is slow, so these calls are not run during routine checks
# \donttest{
# save a gtsummary table as html
tbl |>
save_html(path = tempfile(fileext = ".html"))
#> ✔ Writing /tmp/Rtmph1vU5T/file1c077981902f.html
# save as html with gt
tbl |>
gtsummary::as_gt() |>
save_html(path = tempfile(fileext = ".html"))
#> ✔ Writing /tmp/Rtmph1vU5T/file1c0726c184b8.html
# save as html with custom CSS
tbl |>
gtsummary::as_gt() |>
save_html(
path = tempfile(fileext = ".html"),
css = "body { font-family: Arial; font-size: 12px; }"
)
#> ✔ Writing /tmp/Rtmph1vU5T/file1c0713cb7d9c.html
# save a paginated table as html — pages are separated by a horizontal rule
gtsummary::tbl_split_by_rows(tbl, row_numbers = seq(20, nrow(tbl), by = 20)) |>
save_html(path = tempfile(fileext = ".html"))
#> ✔ Writing /tmp/Rtmph1vU5T/file1c0713419a08.html
# }