-
-
Notifications
You must be signed in to change notification settings - Fork 980
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
RMarkdown child documents not rendering properly: ```{=html} shows in the output #2180
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This special syntax with backtick is appearing due to a change in htmltools. This is used to protect specific HTML part during Pandoc conversion. rmarkdown now ask htmltools to use this special Raw Block syntax for Pandoc. It should not be seen in the output after Pandoc conversion so you may have found a bug. You can deactivate for now this behavior to get the old one that should still work by setting In the meantime we need to understand why this happens. |
Let me makes a few comments on what is going on here. You are calling First problem is that But that being said, let's dig to understand why you see what you see. In a knit rendering, # with htmltools.preserve.raw = FALSE
> knitr::knit(text = c("```{r, echo = FALSE}", "htmltools::HTML('<h1>Hello</h1>')", "```"), quiet = TRUE)
[1] "<!--html_preserve--><h1>Hello</h1><!--/html_preserve-->"
# with htmltools.preserve.raw = TRUE set by default by rmarkdown
> withr::with_options(list(htmltools.preserve.raw = TRUE),
+ cat(knitr::knit(text = c("```{r, echo = FALSE}", "htmltools::HTML('<h1>Hello</h1>\n<p>Content</p>')", "```"), quiet = TRUE))
+ )
```{=html}
<h1>Hello</h1>
<p>Content</p>
``` You can find above the specific syntax you observed. As said above, I believe the conflict comes from the fact that Lets look at this by rendering one of your child from another dummy main Rmd doc ---
title: "test"
output: html_document
---
```{r, comment=""}
library(shiny)
cat(knitr::knit_child('child1.Rmd', quiet = TRUE))
``` The last chunk will output this:
Here is some text describing the chart below
And this is some more text
```{=html}
<div class="container-fluid">
<div class="row">
<div class="col-sm-6">
<div id="outb494fc4cc8988858" class="shiny-plot-output" style="width:100%;height:400px;"></div>
</div>
</div>
</div>
``` As you can see, the raw block bits added for HTML preservation are also added as part of the If we combine the two together, we will have a double preservation by raw block meaning only the outer one will be processed as such by Pandoc ```{=html}
this will be treated as HTML by pandoc, will the outer backticks removed.
```{=html}
And this all block with line above and below will be kept
```
``` We can emulate what happens with this
---
title: "test"
output: html_document
---
```{r, comment=""}
library(shiny)
HTML(knitr::knit_child('child1.Rmd', quiet = TRUE))
```
withr::with_options(list(htmltools.preserve.raw = TRUE),
cat(knitr::knit("test.Rmd", quiet = TRUE))
)
xfun::file_string("test.md")
---
title: "test"
output: html_document
---
```r
library(shiny)
HTML(knitr::knit_child('child1.Rmd', quiet = TRUE))
```
```{=html}
Here is some text describing the chart below
And this is some more text
```{=html}
<div class="container-fluid">
<div class="row">
<div class="col-sm-6">
<div id="outa01a12c987172259" class="shiny-plot-output" style="width:100%;height:400px;"></div>
</div>
</div>
</div>
```
``` The nested raw blocks can be seen above. For me, this explains why you see the inner raw block backticks syntax in your output - they are kept because they are inside of a raw block which tells pandoc to process the content as raw HTML. I think this issue needs to be solve by rethinking the way you split you content and put in back together. If you want to use child document to use I am not a shiny expert so I don't have a correct solution right now. If we want to support this, we need to think more about how this could be done (and possibly have different way to create shiny apps from Rmd that allow splitting content of the UI in several files.) Hope it helps understand. |
I look into what shiny offers to include Markdown in an app. There are
None of the above uses Pandoc, so the raw block syntax will not be support ```{=html}
content
``` Building on the above, and using simple Rmd content, this should work ---
output:
html_document
runtime: shiny
---
```{r, include = FALSE}
render_child <- function(path) {
withr::local_options(list(htmltools.preserve.raw = FALSE))
markdown(knitr::knit_child(path, quiet = TRUE))
}
```
```{r, echo = FALSE}
library(ggplot2)
tabsetPanel(
type = "tabs", id = "x",
tabPanel("child1",
value = "y",
HTML(render_child("child1.Rmd"))
),
tabPanel("child2",
value = "z",
HTML(render_child("child2.Rmd"))
)
)
```
```
I also experimented with using rmarkdown directly to convert the result of ---
output:
html_document
runtime: shiny
---
```{r, include = FALSE}
render_child <- function(path) {
tmp <- tempfile(fileext = ".md")
xfun::write_utf8(knitr::knit_child(path, quiet = TRUE), tmp)
res <- rmarkdown::render(tmp, 'html_fragment', quiet = TRUE) # should we add `envir = knitr::knit_global()` ?
xfun::read_utf8(res)
}
```
```{r, echo = FALSE}
library(ggplot2)
tabsetPanel(
type = "tabs", id = "x",
tabPanel("child1",
value = "y",
HTML(render_child("child1.Rmd"))
),
tabPanel("child2",
value = "z",
HTML(render_child("child2.Rmd"))
)
)
```
The above solution are only experiment from me to understand better how this could / should work. They could work for anyone having this issue but there may be limitation, side effects, conflict, or anything happening. I think it would highly depend on what is inside the child document. Anyway, this is useful to understand better all this child document behavior. |
See SO 68225360
https://stackoverflow.com/questions/68225360/rmarkdown-child-documents-not-rendering-properly-html-shows-in-the-output
We have a big interactive Rmarkdown document using shiny that we split into a parent/child structure to make it easier to manage, as per this guidance. We use tabsetPanel to pull different child documents into different tabs.
This used to work well, but it has recently broken when using R 4.0.4. Still works on my old 3.6.2 version of R.
When you run the parent document, ```{=html} appears at the top of the output, the tabs don't work any more and the text has disappeared. There are also three backticks at the bottom of the output.
screenshot of the output with unexpected bits highlighted
So far I have tried doing this in a different way using the following code from the guide linked above, but I don't think this will work with shiny and the layout we want.
Here's the code for the three R Markdown documents:
a) parent.Rmd
b) child1.Rmd
c) child2.Rmd
a) parent.Rmd
b) child1.Rmd
c) child2.Rmd
And here's my session info:
Checklist
When filing a bug report, please check the boxes below to confirm that you have provided us with the information we need. Have you:
[Y] formatted your issue so it is easier for us to read?
[Y] included a minimal, self-contained, and reproducible example?
[Y] pasted the output from
xfun::session_info('rmarkdown')
in your issue?[Y] upgraded all your packages to their latest versions (including your versions of R, the RStudio IDE, and relevant R packages)?
[Y] installed and tested your bug with the development version of the rmarkdown package using
remotes::install_github("rstudio/rmarkdown")
?The text was updated successfully, but these errors were encountered: