save_html.RdSave 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,
)
# save a gtsummary table as html
tbl |>
save_html(path = tempfile(fileext = ".html"))
#> ✔ Writing /tmp/RtmpVH4Fyk/file1a964eb0cc71.html
# save as html with gt
tbl |>
gtsummary::as_gt() |>
save_html(path = tempfile(fileext = ".html"))
#> ✔ Writing /tmp/RtmpVH4Fyk/file1a962e4b21f7.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/RtmpVH4Fyk/file1a961f796bc6.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/RtmpVH4Fyk/file1a963ccee5b4.html