| gen_grob | R Documentation |
gen_grob() converts a flextable into a Grid Graphics
object (grob) that can be drawn on any R graphic device.
This is the function behind save_as_image() and the
patchwork integration (wrap_flextable()).
Typical uses:
embed a flextable in a ggplot2 plot (via
wrap_flextable() or cowplot)
export a flextable as a PNG or SVG image (via
save_as_image())
Text wrapping and scaling are supported. The fit
argument controls how the table adapts to the available
space (fixed size, auto-fit width, or fill the device).
Not recommended for very large tables because the grid calculations can be slow.
Limitations: equations (as_equation()) and hyperlinks
(officer::hyperlink_ftext()) are not rendered.
Use a 'ragg', 'svglite' or 'ggiraph' device for correct rendering.
gen_grob(
x,
...,
fit = c("auto", "width", "fixed"),
scaling = c("min", "full", "fixed"),
wrapping = TRUE,
autowidths = TRUE,
just = NULL
)
x |
a 'flextable' object, see flextable-package to learn how to create 'flextable' object. |
... |
Reserved for extra arguments |
fit |
Determines the fitting/scaling of the grob on its parent viewport.
One of
|
scaling |
Determines the scaling of the table contents.
One of
|
wrapping |
Determines the soft wrapping (line breaking) method
for the table cell contents. One of
Superscript and subscript chunks do not wrap. Newline and tab characters are removed from these chunk types. |
autowidths |
If |
just |
Justification of viewport layout,
same as |
a grob (gTree) object made with package grid
The size of the flextable can be known by using the method dim on the grob.
It's important to note that captions are not part of the table itself. This means when exporting a table to PNG or SVG formats (image formats), the caption won't be included. Captions are intended for document outputs like Word, HTML, or PDF, where tables are embedded within the document itself.
Other functions for flextable output and export:
df_printer(),
flextable_to_rmd(),
htmltools_value(),
knit_print.flextable(),
plot.flextable(),
print.flextable(),
save_as_docx(),
save_as_html(),
save_as_image(),
save_as_pptx(),
save_as_rtf(),
to_html.flextable(),
wrap_flextable()
library(ragg)
library(gdtools)
register_liberationsans()
set_flextable_defaults(font.family = "Liberation Sans")
ft <- flextable(head(mtcars))
gr <- gen_grob(ft)
plot(gr)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.