When working in RStudio, flextable will be printed in the rstudioviewer pane, the default format is HTML output.
flextable
objects can be rendered in HTML format, Microsoft Word, MicrosoftPowerPoint and PDF.This is where a packages like condformat and formattable come in handy. If you use the condformat package, you can include the table in an RMarkdown generated PDF or HTML document. However, the formattable function, though capable of much prettier output, does not work with PDFs generated using RMarkdown. First, here is a condformat example. Flextable examples. flextable, Function used to render flextable in knitr/rmarkdown documents. HTML a flextable object Rmd') file.copy(demodocx, to = rmdfile, overwrite = TRUE). Asflextable.Rmd Function asflextable is a generic function to cast objects into flextable. 3.3 R Markdown documents. One great feature of flextable is that it can be used in R Markdown documents; HTML, Word, PowerPoint and PDF outputs are managed with method knitr::knitprint. Print the flextable object in the rmarkdown’s render chunk as demonstrated in this document (generated from an R Markdown document).- title: 'flextable formatting' output: rmarkdown::htmldocument.
3.1 Simple export
Adobe indesign for dummies pdf. You can export the tables simply in Word, PowerPoint or HTML or even PNG files.To do this, one of the following functions is used:
- save_as_html
- save_as_pptx
- save_as_docx
- save_as_image
![Flextable Flextable](/uploads/1/3/5/1/135125613/896928397.png)
Package
webshot
or webshot2
is required to save a flextable as animage, see 3.5.1.3.2 In an interactive session
If you have a Word or PowerPoint client on your machine, you can use the
print
methodwith argument preview
set to “pptx” or “docx”. It will produce and open adocument where the table will be printed and ready to go to your clipboard.3.3 R Markdown documents
One great feature of
flextable
is that it can be used in R Markdowndocuments; HTML, Word, PowerPoint and PDF outputs are managed withmethod knitr::knit_print
.Print the
flextable
object in the rmarkdown’s render
chunkas demonstrated in this document (…generated from an R Markdowndocument).3.3.1 Looping in R Mardown documents
Some codes do not trigger the
knitr::knit_print
method. This isthe case, for example, of for loop
inside a chunk R.In this case, you can use
flextable_to_rmd
that will printthe raw code adapted to the output format. Chunk option results
must be set to asis
.3.3.2 pandoc versions
Supported formats require some minimum pandoc versions:
3.3.3 Notes about rmarkdown::word_document
![Flextable Flextable](https://www.bioinfo-scrounger.com/data/photo/rmarkdown_support.png)
This note is only relevant when using flextable in an R Markdown document with Word output.
In some context,
officedown::rdocx_document()
will have to be used insteadof rmarkdown::word_document()
. This is because Word doesn’t store hyperlinks or imagesin the main document but stores references. This is not managed by rmarkdown unlessofficedown::rdocx_document()
is used.If you don’t add images or hyperlinks in a flextable rendered by
officedown::rdocx_document()
thenyou can forget about that.3.3.4 Notes about rmarkdown::pdf_document
The PDF version of the flextable ignore some featuresof flextable, here is the list of unsupported/ignored options(they may be implemented later):
- padding is not taken into account (it is instead recommendedto use the arguments
ft.tabcolsep
andft.arraystretch
), - the borders can only be full (no dash for example),
- the height of the lines cannot be defined.
- line spacing is not yet implemented.
In order to be able to change latex font in a flextable,PDF engine should be specified by adding
latex_engine: xelatex
in the YAML header of the R Markdown document. The default onepdflatex
does not enable the use of system fonts.3.4 PowerPoint or Word documents with officer
To add these objects in PowerPoint or Word documents, use functions:
ph_with()
(PowerPoint)body_add_flextable()
(Word)
Flextable R Markdown Software
The following is producing a PowerPoint document:
The following is producing a Word document:
3.5 R graphics
3.5.1 Dependency for images
Beeing able to save flextable as an image is requiring package
webshot
or webshot2
to be available. Read more about it here.3.5.2 What will be the size?
Rmarkdown Flextable Caption
In some case, you may want to know the exactwidth and height of the table to be sure to set up the correct aspect ratio. Thefunction
flextable_dim()
will provide these informations without the need toproduce the image.Results are in inches. You can reuse them as values for knitr chunk options
fig.asp
, fig.width
and fig.height
.3.5.3 As an R graphic
To get a plot from a
flextable
object, use function plot
.3.5.4 With ggplot
You can also add the flextable (with
grid::rasterGrob()
andggplot2::annotation_custom()
) in a ggplot object. You need first to useas_raster()
function that will return a raster version of the flextable.Gitscout. Gitscout is a neat macOS application that helps you establish a connection with your GitHub account and enables you to view and manage issues related to your projects. 14 likes 2 talking about this. Gitscout is a beautiful and optimized Github issues manager for OSX. Gitscout is a beautiful GitHub Issues experience for macOS Try it now. Browse, organize and manage your GitHub Issues. Gitscout provides a beautiful new experience to stay organized and get your work done. 'Save' any issue in one click and stay focused Blazing fast navigation across. Key Action / Focus the search bar: Esc: Focus the search bar and cleans it ↓ Select the next search result ↑ Select the previous search result: Enter: Open the selected search result.
3.6 Using within shiny applications
Flextable R Markdown Tutorial
Use function
htmltools_value()
to get the html value of theflextable. This value is suitable for an shiny::uiOutput()
.