'Export flextable as html
If I print a flextable object, it get displayed as html in a browser. Is there a way of saving the html. I am using 0.5.1 version of flextable.
Solution 1:[1]
You can produce an HTML document containing a flextable with R Markdown. The following is extracted from the documentation - this is how flextable can be used in R Markdown documents:
> this is how to print a flextable in a R Markdown document
```{r eval=FALSE}
library(magrittr)
mytable <- cars %>%
head() %>%
flextable() %>%
autofit()
mytable
```
Solution 2:[2]
Update November 2019: the function is now available in the package version 0.5.6
ft <- flextable(mydataframe) # create a flextable object
save_as_html(ft, "path/to/file.html") # and save as html
From the documentation: https://rdrr.io/cran/flextable/man/save_as_html.html
Solution 3:[3]
The provided answers require users to export (i.e. save) the flextable.
To 'just' transform a flextable object to HTML, use their htmltools_value() function:
library(dplyr) # for the pipe
library(flextable)
mtcars %>%
flextable() %>%
htmltools_value()
This is ideal for adding a flextable to e.g. an email object (using the blastula package or the Microsoft365R package for example).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David Gohel |
| Solution 2 | Mesozoik |
| Solution 3 | MS Berends |
