Skip to contents

The gt_double_table function takes some data and a user-supplied function to generate two tables in a list. To convert existing gt::gt() code to a function, you can follow the approximate pattern: gt_fn <- function(x){gt(x) %>% more_gt_code}

Your function should only have a single argument, which is the data to be supplied directly into the gt::gt() function. This function is intended to be passed directly into gt_two_column_layout(), for printing it to the viewer, saving it to a .png, or returning the raw HTML.


gt_double_table(data, gt_fn, nrows = NULL, noisy = TRUE)



A tibble or dataframe to be passed into the supplied gt_fn


A user-defined function that has one argument, this argument should pass data to the gt::gt() function, which will be supplied by the data argument. It should follow the pattern of gt_function <- function(x) gt(x) %>% more_gt_code....


The number of rows to split at, defaults to NULL and will attempt to split approximately 50/50 in the left vs right table.


A logical indicating whether to return the warning about not supplying nrows argument.


a list() of two gt tables


# define your own function
my_gt_function <- function(x) {
  gt(x) %>%
    gtExtras::gt_color_rows(columns = mpg, domain = range(mtcars$mpg)) %>%
    tab_options(data_row.padding = px(3))

two_tables <- gt_double_table(mtcars, my_gt_function, nrows = 16)

# list of two gt_tbl objects
# ready to pass to gtExtras::gt_two_column_layout()
str(two_tables, max.level = 1)

#> List of 2
#> $ :List of 16
#> ..- attr(*, "class")= chr [1:2] "gt_tbl" "list"
#> $ :List of 16
#> ..- attr(*, "class")= chr [1:2] "gt_tbl" "list"

Function ID