-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
flextable won't work with quarto files (.qmd) after rendering to html #385
Comments
I've been investigating this and can't quite discern what the problem is. I do notice that there is quite a bit of custom detection logic in the |
I found something that may be the reason, HTML output is using shadow dom by default with flextable and the content is in a tag It seems the content of these tag is removed in the HTML result with quarto. ---
format: html
---
```{r}
#| results: asis
#| echo: false
cat("<template><div>zzz</div></template>")
```
```{r}
#| results: asis
#| echo: false
cat("<div>zzz</div>")
``` Generated HTML fragment with quarto <main class="content" id="quarto-document-content">
<template></template><p></p>
<div>
zzz
</div>
</main> |
You can set knitr chunk option
|
It does indeed look like our DOM post-processor mauls the |
There are side effects. In the following example, I voluntarily added a CSS definition that conflicts with one of those of flextable because the result is not encapsulated in a shadow-dom.
Expected result is: Quarto result is: I am ok with the fix you proposed, but I think it would be easier if I could do it. For example, is there a way to know if running quarto (sorry I am totally new to quarto and am a bit lost in the repo for now)? If yes, I can now switch to |
That sounds good. Here is where we set various https://github.com/quarto-dev/quarto-cli/blob/main/src/resources/rmd/execute.R#L179-L185 Another Quarto related item to check on is handling of table cross-references and captions. AFAIK is should work fine (we can target raw HTML, looking for the |
I was thinking it might be better if I put the temporary workaround into Quarto for a couple of reasons:
Here is my patch to Quarto: quarto-dev/quarto-cli@d2b4ea2 (it just sets |
Thank you guys for help... Now all works fine after Quarto patch. |
@jjallaire it's ok for me, thanks for the fix, it's great. Also, thanks for the pointer to caption and cross-ref, I'll explore that soon and will try to give feedback. |
In terms of labels for table cross refs, in Quarto they are included within the table caption. So for example here is a raw HTML table that is reference-able: <table class="table">
<caption>Simple Table {#tbl-simple}</caption>
<thead>
<tr class="header">
<th>Col1</th>
<th>Col2</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>A</td>
<td>B</td>
</tr>
</tbody>
</table>
See @tbl-simple for details. So its certainly possible for crossrefs to work straight away w/ flextable if users explicitly specify the caption (I believe that's how it currently works w/ bookdown). In addition, we wanted to make it possible to specify the caption and label as cell options (for consistency w/ figures). That would look something like this: ```{r}
#| label: tbl-simple
#| tbl-cap: "Simple Table"
library(flextable)
mtcars |>
head() |>
flextable()
``` In this case we look at the raw HTML and see if we can modify an existing caption (or inject a new one). We do that here: https://github.com/quarto-dev/quarto-cli/blob/main/src/resources/filters/quarto-pre/table-captions.lua#L165-L185. If you want to play w/ getting this to work for flextable its pretty straightforward:
Note that it's not entirely imperative that this work w/ flextable (as manually specifying a |
Unfortunately captions for flextables still don't work.
and I've got but when I code in the same file
I've got What I done wrong? Remark: I have the latest RStudio version which should fix this problem! |
It looks like flextable creates two separate html outputs so we are missing them in our code. Here I've merged adjacent raw HTML cells that have tables (which in turn makes the example above work as expected): quarto-dev/quarto-cli@9e9f7b3 |
This issue seems to still occur when rendering in Word: Is this expected, or can a fix be applied for rendering in Word too?
|
It should be OK now, not yet on CRAN (next week probably). Note I am using the dev version of Quarto, captions in Word were the big deal, and it may change in the future, we will adapt if necessary. :) |
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary. |
flextable
function won't show tables after rendering qmd files to html, but for pdf and docx works. If I write the following codein qmd file and compile it, I've got this
If I compile file to pdf and docx function works.
Can you help me?
The text was updated successfully, but these errors were encountered: