Take data, a gt-generating function, and create a list of two tables
Source:R/two-column-layouts.R
gt_double_table.Rd
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.
Arguments
- data
A
tibble
or dataframe to be passed into the suppliedgt_fn
- 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 thedata
argument. It should follow the pattern ofgt_function <- function(x) gt(x) %>% more_gt_code...
.- nrows
The number of rows to split at, defaults to
NULL
and will attempt to split approximately 50/50 in the left vs right table.- noisy
A logical indicating whether to return the warning about not supplying
nrows
argument.
Value
a list()
of two gt
tables
Examples
library(gt)
# 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"
See also
Other Utilities:
add_text_img()
,
fa_icon_repeat()
,
fmt_pad_num()
,
fmt_pct_extra()
,
fmt_symbol_first()
,
generate_df()
,
gt_add_divider()
,
gt_badge()
,
gt_duplicate_column()
,
gt_fa_column()
,
gt_fa_rank_change()
,
gt_fa_rating()
,
gt_fa_repeats()
,
gt_highlight_cols()
,
gt_highlight_rows()
,
gt_img_border()
,
gt_img_circle()
,
gt_img_multi_rows()
,
gt_img_rows()
,
gt_index()
,
gt_merge_stack_color()
,
gt_merge_stack()
,
gt_two_column_layout()
,
gtsave_extra()
,
img_header()
,
pad_fn()
,
tab_style_by_grp()