Questions tagged [gt]

Use this tag for questions related to the gt package. The gt package provides functions to make it easy to create and style tables in the R programming language.

The package provides functions to make it easy to create and style tables in the programming language. Like the grammar of graphics for data visualization (see ), the philosophy behind is to provide a grammar of tables.

An overview and introduction to the package can be found on the package website.

429 questions
12
votes
1 answer

gt table - newline in cell

I try to force a newline in a gt cell using R gt package. In gt documentation it is described as possible to do it for column labels using cols_label() # example gt_tbl %>% cols_label( col = html("text1,
text2") ) But in cells I could…
Nicolas Rosewick
  • 1,938
  • 4
  • 24
  • 42
10
votes
2 answers

Conditional formatting of multiple columns in gt table

This is my first post, so apologies if I messed something up. I am trying to apply conditional formatting to multiple columns (comparing results for samples SampA, SampB and SampB to Limit) of a gt table. Following the lead of one of the gt examples…
gsm
  • 103
  • 1
  • 6
9
votes
1 answer

gt tables in Quarto Pub without slide CSS styling

I am new to making revealjs slides using Quarto in R and RStudio. I would like to include a {gt} table (https://gt.rstudio.com/) on a slide with the default gt styling. But the issue I am running into is that the table is HTML and inherits custom…
Daniel D. Sjoberg
  • 8,820
  • 2
  • 12
  • 28
8
votes
1 answer

Printing gt table inside a loop with rmarkdown::render not working

I am programming a report generator that export html. I use two files, the first is a loop that will determine the number of reports and within my .Rmd template I have another loop to print several tables. The .Rmd below, works fine --- title:…
jcarlos
  • 425
  • 7
  • 17
8
votes
0 answers

gt table - freeze columns (or make them more readable)

I am creating a table using the gt package in R Studio, and I can't figure out a graceful way to make the columns more readable for tables with many rows. Take the following code: gt::sp500 %>% slice(1:100) %>% mutate(month =…
BSHuniversity
  • 264
  • 1
  • 6
7
votes
1 answer

"Error in s$close() : attempt to apply non-function" when calling `gtsave()`

I use the gt package to create and save a table that I produce. Recently, I have sometimes been getting the following error when I attempt to gtsave. Error in s$close() : attempt to apply non-function Here is session information: > sessionInfo() R…
melmo
  • 757
  • 3
  • 15
7
votes
2 answers

Is there a way to embed a ggplot image dynamically by row (like a sparkline) using the gt package?

I'm trying to replicate this process and get the gt package to render ggplot objects where each row in the table gets a different graph (like a spark line). There appears to be a solution on the linked page, but when I try to replicate it, I get the…
6
votes
1 answer

Scale Quarto PDF table output to fit page

How can I scale a table to fit a PDF page in Quarto? Example: --- title: "Untitled" format: pdf --- ```{r setup} #| include: false library(dplyr) library(gt) ``` ```{r tbl} #| include: true #| echo: false tibble(a = 1000, b = 2000, c = 3000, d…
nicholas
  • 903
  • 2
  • 12
6
votes
0 answers

Saving table with gtsave() to .RTF file yields different table output? R

I am using the gt package to make a table ad saving it as an .RTF. I'm using the function gt::gtsave() but the table saved looks very different from what is in my viewer or outputs to HTML. Lin: to documentation I am…
RL_Pug
  • 697
  • 7
  • 30
6
votes
0 answers

Grouping a gt table by two factors

Much like this poster, I am trying to make a table in r where I am grouping by levels of a factor. I am happy to do this in gt or kabbleExtra or any other package which makes a graph like this possible. I would like to take the graph from the first…
6
votes
5 answers

Error: package or namespace load failed for ‘gt’: object ‘faststack’ is not exported by 'namespace:fastmap'

I'm getting that error message when running library(gt) Help would be appreciated
Jorge Lopez
  • 467
  • 4
  • 10
6
votes
2 answers

Color a column by another column's value

I would like to create a gt table where I display numeric values from two columns together in a single cell, but color the cells based on just one of the column's values. For example using the ToothGrowth example data I'd like to put the len and…
qdread
  • 3,389
  • 19
  • 36
6
votes
0 answers

gt table save to Word

Currently the gtsave function in the gt package does not support MS-Word. I tried converting a gt object to a flextable object to then save as word, but flextable doesn't support a gt object. And when I just copy paste an html to Word, the…
Ed_Gravy
  • 1,841
  • 2
  • 11
  • 34
6
votes
1 answer

R gt table formatting: How can I take my long gt table and make it wide?

I would like to take a gt() table and transform it to a "wide" format instead of a "long" format by group level. So for, as an example using the iris data set: library(dplyr) library(gt) iris %>% group_by(Species) %>% …
igutierrez
  • 113
  • 7
6
votes
1 answer

How to conditionally format a cell in a [gt] table based on the value of the cell

The gt package lets users easily format cells based on conditional statements about the rows. I'm looking for a way to format each cell based on the value in the cell. Here's what I mean. In the table below, I'd like to color each cell with S&P…
John J.
  • 1,450
  • 1
  • 13
  • 28
1
2 3
28 29