I'm attempting to add a table into an RMarkdown Powerpoint Presentation using the kableExtra package. Initially, I tried to run the code without always_use_html in my YAML and the following error appeared.
Error: Functions that produce HTML output found in document targeting pptx output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your rmarkdown file:
always_allow_html: true
Note however that the HTML output will not be visible in non-HTML formats.
Execution halted
After adding always_allow_html to my YAML, my table is still not appearing as desired in my slide .
My table should look something like this
Does anyone perhaps know how to embed a kableExtra table in Rmarkdown slides?
Here is my full code
---
title: "Untitled"
output: powerpoint_presentation
always_use_html: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Table
```{r table}
library(kableExtra)
data <- data.frame(a = c(1,2,3), b = c(4,5,6))
data %>%
kable() %>%
kable_styling()
```
Try kbl() instead of kable():
library(kableExtra)
data <- data.frame(a = c(1,2,3), b = c(4,5,6))
data %>%
kbl() %>%
kable_styling()
kable() renders to html in the viewer pane when run live, and can knit to html.
Office docs don't handle the html.
Options
include, pass a table to the default powerpoint style for your document with .rmd.
See:https://support.rstudio.com/hc/en-us/articles/360004672913-Rendering-PowerPoint-Presentations-with-the-RStudio-IDE
use officer with officemarkdown
Officer bookdown summary
-advanced styling to build a custom template can be done for reproducible
-you can save to powerpoint, then use table style editing to tweak, vs. setting the styling with style_type, style_id,style_name parameters in officedown
Related
Any recommendations for rendering tables serverless with {rmarkdown}? I need to do this so I can push the rendered HTML to a Confluence page with the help of {conflr}.
When I render something like the below in an RMD file and then try to send to Confluence using conflr:::confl_create_post_from_Rmd_addin(), I get this error:
output file: serverless_test.knit.md
Error: Functions that produce HTML output found in document targeting commonmark-yaml_metadata_block output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your rmarkdown file:
always_allow_html: true
Note however that the HTML output will not be visible in non-HTML formats.
After adding the suggested flag, the table still does not render.
If I try to run it locally without pushing to Confluence using DT:renderDT(..., server = FALSE), I get a warning This R Markdown document contains Shiny content, but was rendered to a static file. Shiny content in the document may not appear, and will not be interactive. In addition, the filter = "top" renders the text box at top of each column to filter column contents, but when you enter text nothing happens.
---
title: "serverless_dt"
author: "Matt Wood"
date: "2022-08-17"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=TRUE)
library(tidyverse)
library(DT)
```
```{r}
DT::datatable(iris)
# %>% DT::renderDT(server = FALSE)
```
conflr:::confl_create_post_from_Rmd_addin()
Thanks for any help!
The problem is that DataTables(DT) library is a htmlwidgets thing which isn't supported by conflr.
You can use only static content with the chunk option screenshot.force = TRUE
Using quarto's HMTL-output functionalities, I am trying to produce a kable from a data.frame that contains some Markdown-style formatting that should show up in the final document. In the actual use case, I have a number of documents already formatted this way and I would like re-use these commands for correctly rendering the output.
Here's my example.qmd:
---
title: "example"
format:
html
---
```{r setup}
library(kableExtra)
```
```{r}
#| echo: false
data.frame(Function = "`read_delim()`",
Formula = "$\\leftarrow$",
Break = "this continues on a<br>new line",
Link = "[Google](www.google.com)") |>
kbl(format = "html")
```
After running the chunk, the preview in RStudio does display the arrow and line break correctly, but ` ` and the link fail to have an effect:
When rendering the qmd to HTML, the result looks like this, i.e. ignores the formatting:
What am I missing? Is there a way to include such formatting commands into a kable when rendering a quarto document to HTML?
When creating a table in Quarto, you can't mix Markdown with HTML - the Markdown syntax won't be processed within the HTML table.
This R code would work
data.frame(Function = "`read_delim()`",
Formula = "$\\leftarrow$",
Break = "this continues on a<br>new line",
Link = "[Google](www.google.com)") |>
kbl(format = "markdown")
So if you can, output only Markdown table which knitr::kable() should do by default.
If you need to output a HTML table (e.g for specific HTML features), you need to use a framework that will render the markdown for you while creating the HTML table.
gt with fmt_markdown() and md()
flextable with ftextra and colformat_md() or as_paragraph_md
This is possible that this limitation of note being able to include raw Markdown inside HTML table will be improve in the future (https://github.com/quarto-dev/quarto-cli/discussions/957#discussioncomment-2807907)
I want to use bold and italics in a flextable caption. I know that it is possible to apply font syles to text within the header or body of a flextable using the ftExtra package and one can choose different output styles for a caption in word output by officeR. But either these do not work with the caption (ftExtra) or do not provide a style that allows selective application of bold and italics.
Here is some code with the intended markdown in the caption:
library(flextable)
library(dplyr)
iris[1:10,] %>%
flextable() %>%
set_caption(caption = "**Tab. 1:** First ten (*n* = 10) samples of the Iris species dataset")
The caption should read as "Tab. 1: First ten (n = 10) samples of the Iris species dataset"
UPDATE
based on the comment by dario a possible solution would be:
library(flextable)
library(dplyr)
iris[1:10,] %>%
flextable() %>%
add_header_lines("") %>%
compose(
i = 1, part = "header",
value = as_paragraph(
as_chunk("Table 1: ", props = fp_text(bold = TRUE)),
as_chunk("First ten ("),
as_chunk("n", props = fp_text(italic = TRUE)),
as_chunk(" = 10) samples of the Iris species dataset")
)
)
Thank you very much. In the end I need to produce about 20 tables in different chapters and so I will try the suggestion by David to build the captions during knitting a markdown. But it is good to know that there is way, although clunky and not flexible using compose.
I prepared a markdown template for you:
---
title: "Hello World"
header-includes:
- \usepackage{caption}
output:
pdf_document:
latex_engine: xelatex
---
```{r, include = FALSE}
library(flextable)
library(dplyr)
table2 <- flextable(mtcars[1:5, 1:6])
```
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
\begin{table}[hbtp]
\captionof{table}{Text of the caption.}
`r table2`
\end{table}
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
An output
I'm using Flextable to make pretty tables in a Word doc that gets created in rmarkdown. The tables are all aligned in the center of the doc. I'd like them aligned on the left.
I know body_add_flextable has an align argument, but that function appears to be for inserting a flextable into an existing doc, and not for using within an rmarkdown file creating the doc.
I also have a reference_docx file where I can adjust styles, but tables get inserted as "normal" style, and I can't adjust the table without adjusting everything else in the doc with the "normal" style.
Here's an example rmarkdown file:
---
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(flextable)
```
```{r cars}
exampleDF <- data.frame("Col1" = c(1:3), "Col2" = c(4:6))
example.flex <- flextable(exampleDF)
example.flex
```
Also, I'm fairly new to using both rmarkdown and Flextable, and this is my first StackOverflow question. So all kinds of apologies if this is a stupid/poorly phrased question.
Dunno if this is a new feature, but you can do this following the online vignette, by adding ft.align = ... to the chunk options.
I think the same holds true for word documents. I am posting this with html as an answer so I can share a screenshot as a result (don't use word) and also the question was not specifically for word (in the title).
---
output: html_document
---
```{r setup, include=FALSE}
library(flextable)
```{r cars, ft.align = "left"}
exampleDF <- data.frame("Col1" = c(1:3), "Col2" = c(4:6))
example.flex <- flextable(exampleDF)
example.flex
I don't think I understand how table rendering works inline in R Notebooks, and how kable output is formatted inline as well.
I'd just like to be able to see dataframes in my notebook's inline output the way they appear when previewing the notebook / knitting the file.
What the table looks like in Notebook Preview:
I've tried turning off the paged print option, but still get it as seen below:
```{r results='asis', rmarkdown.df_print = FALSE}
ssc.sample.convert %>% tabyl(Role) %>% as.data.frame()
```
When attempting to use kable, I can't seem to get the output to look like it does in the rendered HTML file:
```{r results='asis', rmarkdown.df_print = FALSE}
ssc.sample.convert %>% tabyl(Role) %>% kable(format="html")
```
Is it possible to get rid of the paged print somehow?
Is it possible to view the final output of kable tables inline?