4

I am trying to render a .qmd file to HTML specifying an output file. I am compiling it from a Quarto Project from RStudio on MacOS 12.6. I also have a bootstrap theme in the YAML header.

---
title: "quarto_output_experiment"
format:
  html:
    theme: journal
---

If I render it with Cmd + Shift + K from RStudio, the HTML document appears in the same directory as the .qmd and looks fine. However if I render it from the Quarto CLI specifying the output directory (a folder called output), the HTML can't render plots and lacks any sort of formatting and style. The command is

quarto render quarto_output_experiment.qmd --output output/report.html

Here are the results.

This is when rendered from RStudio This is when render via Quarto CLI
Nice HTML Broken HTML

What am I missing? How can I render the HTML in a different directory and have plots and proper style?

For reference, this is the document itself

---
title: "quarto_output_experiment"
format:
  html:
    theme: journal
---

## Quarto

Quarto enables you to weave together content and executable code into a finished document.
To learn more about Quarto see <https://quarto.org>.

```{r}
1 + 1
```

# Lorem ipsum

```{r}
library(ggplot2)
ggplot(data.frame(x = rnorm(100)), aes(x)) + geom_density()
```

UPDATE

Specifying --output-dir intead of --output produces a document with plots and style, but the question still remains if there is a way to change the name of the output HTML file? Probably not mission critical, but I'm still curious.

Álvaro
  • 564
  • 5
  • 13

1 Answers1

4

That is a really weird bug and it seems to be related to the path (see here. Usually, you can use quarto::render_quarto() like this,

quarto::quarto_render(input = "quarto_output_experiment.qmd", output_file = "report.html")

This works, but when you add the folder name

quarto::quarto_render(input = "quarto_output_experiment.qmd", output_file = "results/report.html")

it does not work anymore. The problem is that the folder (quarto_output_experiment_files) where the libs and images are stored, is not automatically also placed where the output-file is located.

I would file an issue here.

A possible solution for the time being would be the self-contained param that produces self-contained html files, e.g.

---
title: "quarto_output_experiment"
format:
  html:
    theme: journal
    self-contained: true  
---

then you could use file.copy to move that file in the correct folder.

Edit: The option self-contained is depreciated, use embed-resources instead! Link

Julian
  • 6,586
  • 2
  • 9
  • 33