How to output a gt table object into a rmarkdown document?

I'm looking for examples showing how to output a gt table in a rmarkdown (*.RMD) document. My particular RMD document produces a PDF, but I am looking for general examples.


To see a case study of how gt tables look in HTML, go here.

I'm also attaching a PDF version of the examples linked above. There's apparently still some work to be done with specifying the width in LaTeX format (see this GitHub issue).

case_study_gtcars.pdf (302.9 KB)

Thanks for the resources @jdb . I'll take a look.

1 Like

Dear all,

I was looking at this package and the links posted here. I am failing to see how to include a gt table in a RMarkdown document for either PDF or HTML output.

Any of you managed to produce a working sample?



What is your specific problem? Including a gt table in a rmarkdown document is as easy as this

title: "gt example"
output: html_document

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
# Example from the gt github page
```{r gt table}
# Define the start and end dates for the data range
start_date <- "2010-06-07"
end_date <- "2010-06-14"

# Create a gt table based on preprocessed
# `sp500` table data
sp500 %>%
  dplyr::filter(date >= start_date & date <= end_date) %>%
  dplyr::select(-adj_close) %>%
  dplyr::mutate(date = as.character(date)) %>%
  gt() %>%
    title = "S&P 500",
    subtitle = glue::glue("{start_date} to {end_date}")
  ) %>%
    columns = vars(date),
    date_style = 3
  ) %>%
    columns = vars(open, high, low, close),
    currency = "USD"
  ) %>%
    columns = vars(volume),
    scale_by = 1 / 1E9,
    pattern = "{x}B"

A post was split to a new topic: How to output a gt table object into a rmarkdown document -> PDF?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.