tab_1 <-
gtcars |>
dplyr::select(model, year, hp, trq) |>
dplyr::slice(1:5) |>
gt(rowname_col = "model") |>
tab_stubhead(label = "car")The gtsave() function
Using a small subset of the gtcars dataset, we can create a gt table with row labels. We’ll add a stubhead label with the tab_stubhead() function to describe what is in the stub.
Export the gt table to an HTML file with inlined CSS (which is necessary for including the table as part of an HTML email) using gtsave() and the inline_css = TRUE option.
tab_1 |> gtsave(filename = "tab_1.html", inline_css = TRUE)By leaving out the inline_css option, we get a more conventional HTML file with embedded CSS styles.
tab_1 |> gtsave(filename = "tab_1.html")Saving as a PNG file results in a cropped image of an HTML table. The amount of whitespace can be set with the expand option.
tab_1 |> gtsave("tab_1.png", expand = 10)file:////tmp/RtmpSo95lj/file261239c004f3.html screenshot completed
Any use of the .tex, .ltx, or .rnw will result in the output of a LaTeX document.
tab_1 |> gtsave("tab_1.tex")With the .rtf extension, we’ll get an RTF document.
tab_1 |> gtsave("tab_1.rtf")With the .docx extension, we’ll get a word/docx document.
tab_1 |> gtsave("tab_1.docx")