Rmd render as html not displaying visuals

I have an Rmd script that includes some visualizations. When I run each chunk one by one during development I see the visuals display as expected in Rstudio.

But when I select knit > render as html, the analysis generates an html doc but the visuals are missing.

I tried running the example Rmd file that's generated when one selects to create a new Rmd file, the one with a summary of mtcars and plot(pressure). When I render this doc as html the visuals do render in the resulting html doc.

I'm convinced this is to do with the chunk options I have set. Here is what I have, any pointers or guidance most welcome.

(Note the backslash '' in front of the ticks ` below are not actually in my script, they are there just to get the example blocks to render as close to correct as I can get.)

\```{r setup, include=FALSE}
knitr::opts_chunk$set(
	message = FALSE,
	warning = FALSE,
	include = FALSE
)
pacman::p_load(tidyverse, CLVTools, lubridate, glue, Metrics)
\```

Block with a visual that shows no visual when rendering as html:

\```{r analysis, echo=TRUE, message=FALSE, warning=FALSE}
analysis %>% pivot_wider(names_from = c(func, cut_off), values_from = mae_trans:auc, names_sep = " ") %>% DT::datatable()
\```

Another one:

\```{r visualization, echo=TRUE, message=FALSE, warning=FALSE}
metrics <- analysis %>% select(mae_trans:auc) %>% names
metrics %>% map(~ ggplot(analysis, aes(x = MONETIZATION_WEEK_COHORT, y = get(.x), color = func)) + geom_line() + ylab(.x))
\```

Why do the DT::datatable and ggplot visuals show when running a chunk individually but not when I render the doc as html as a whole?

Hi @dougfir,

It is most likely due to your include = FALSE global chunk option. See the description of the chunk option (found here):

include : ( TRUE ; logical) Whether to include the chunk output in the output document. If FALSE , nothing will be written into the output document, but the code is still evaluated and plot files are generated if there are any plots in the chunk, so you can manually insert figures later.

Side note: on this website you can wrap Rmd code chunks in 4 back-ticks to show the chunk as it actually shows in the R Markdown document (like below).

````
```{r}
head(mtcars)
```
````

Shows up as

```{r}
head(mtcars)
```
1 Like

Got it Matt, thanks for this.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.