Hi,
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.
Thanks
AB
Hi,
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.
Thanks
AB
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)
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?
Regards,
jm
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)
library(gt)
library(tidyverse)
library(glue)
```
# 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() %>%
tab_header(
title = "S&P 500",
subtitle = glue::glue("{start_date} to {end_date}")
) %>%
fmt_date(
columns = vars(date),
date_style = 3
) %>%
fmt_currency(
columns = vars(open, high, low, close),
currency = "USD"
) %>%
fmt_number(
columns = vars(volume),
scale_by = 1 / 1E9,
pattern = "{x}B"
)
```
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.