r-wasm / quarto-live

WebAssembly powered code blocks and exercises for both the R and Python languages in Quarto documents
https://r-wasm.github.io/quarto-live/
MIT License
100 stars 6 forks source link

No runnable code chunks in Quarto books #38

Closed CyuHat closed 1 month ago

CyuHat commented 1 month ago

Dear authors,

First of all, thank you for this excellent extension. I've tested it and think it is great. I will definitly use it for future contents!

I wanted to let you know about a problem I encountered when trying to use it in a quarto book. When I try to install the extension in a quarto book project using quarto add r-wasm/quarto-live, I get the following error after the first question in the installation process:

Quarto extensions may execute code when documents are rendered. If you do not trust the authors of the extension, we recommend that you do not install or use the extension.
? Do you trust the authors of this extension (Y/n) » Yes

ERROR: Include directive failed.
  in file C:\Users\hategeki\Desktop\CODE\R\Projets\WEBSITES\test-quarto-live\test-quarto-live-2\index.qmd,
  could not find file C:\Users\hategeki\Desktop\CODE\R\Projets\WEBSITES\test-quarto-live\test-quarto-live-2\_extensions\r-wasm\live\_knitr.qmd.

Stack trace:
  in file C:\Users\hategeki\Desktop\CODE\R\Projets\WEBSITES\test-quarto-live\test-quarto-live-2\index.qmd,
  could not find file C:\Users\hategeki\Desktop\CODE\R\Projets\WEBSITES\test-quarto-live\test-quarto-live-2\_extensions\r-wasm\live\_knitr.qmd.
    at retrieveInclude (file:///C:/Users/hategeki/AppData/Local/Programs/Quarto/bin/quarto.js:39440:19)
    at standaloneInclude (file:///C:/Users/hategeki/AppData/Local/Programs/Quarto/bin/quarto.js:39476:11)
    at processMarkdownIncludes (file:///C:/Users/hategeki/AppData/Local/Programs/Quarto/bin/quarto.js:39706:38)
    at expandIncludes (file:///C:/Users/hategeki/AppData/Local/Programs/Quarto/bin/quarto.js:39735:11)
    at eventLoopTick (ext:core/01_core.js:153:7)
    at async projectResolveFullMarkdownForFile (file:///C:/Users/hategeki/AppData/Local/Programs/Quarto/bin/quarto.js:40370:25)
    at async fileExecutionEngine (file:///C:/Users/hategeki/AppData/Local/Programs/Quarto/bin/quarto.js:41840:26)
    at async findInputs (file:///C:/Users/hategeki/AppData/Local/Programs/Quarto/bin/quarto.js:92008:36)
    at async findChapters (file:///C:/Users/hategeki/AppData/Local/Programs/Quarto/bin/quarto.js:92037:13)
    at async bookRenderItems (file:///C:/Users/hategeki/AppData/Local/Programs/Quarto/bin/quarto.js:92040:5)

To get around this, I simply install the extension in another project and copy the _extensions folder into the quarto book folder. But when I generate the final book, I realize that the extension does not work, i.e. the {webr} boxes are not considered as usable code zones rather plain code.

Do you know why this problem occurs and how to fix it?

Thanks in advance!

coatless commented 1 month ago

@CyuHat could you double-check the version of Quarto you have? You may need to update RStudio (which has a built-in version of Quarto) or directly update Quarto itself:

georgestagg commented 1 month ago

In addition, be sure that you are using the live-html version of the HTML format, rather than just the plain html format, in your book's _quarto.yml file. e.g.

format:
  live-html:
    theme: cosmo
  pdf:
    documentclass: scrreprt

This kind of problem should probably be listed in some form of FAQ in the documentation.

CyuHat commented 1 month ago

Thank you both for your answers! I tried your solutions but it still does not work. Also I should have given more context. Here are the version I am working with:

R: 4.2.1 Rstudio: 2024.04.2 Quarto: 1.5.55

After updating quarto to the version 1.5.56, the problem persisted. In fact, since the begining it worked for single page html or quarto website, but it still do not works for quarto book. I have done two examples, one using quarto website (see here) and the other one using quarto book (see here). Looking at the final results, it works for quarto web site (see here) but does not work for quarto book (see here).

I kept all the default options for both cases, but here are the changes I have for the quarto website (note: there is no "\" added to the original code chunks):

index.qmd

---
title: "test-quarto-live-1"
engine: knitr
format: live-html
---

{{< include ./_extensions/r-wasm/live/_knitr.qmd >}}

\```{webr}
fit = lm(mpg ~ am, data = mtcars)
summary(fit)
plot(fit)
\```

And here are the changes I have done for the quarto book version:

.github/workflows/quarto-publish.yml

- name: Set up Quarto
        uses: quarto-dev/quarto-actions/setup@v2
        with:
          version: 1.5.56
          tinytex: true

_quarto.yml

format:
  html-live:
    theme: cosmo
  pdf:
    documentclass: scrreprt

index.qmd

---
title: A Quarto Live Document
engine: knitr
format: live-html
---

{{< include ./_extensions/r-wasm/live/_knitr.qmd >}}

\```{webr}
fit = lm(mpg ~ am, data = mtcars)
summary(fit)
plot(fit)
\```

My concern is that I can't get the extension using the command in a quarto book project and after adding the folder manually, it still doesn't work.

georgestagg commented 1 month ago

Please could you double check the contents of your _quarto.yml file? The format should be live-html, but you seem to have html-live.

CyuHat commented 1 month ago

Yes, you are right, it is working now. Thank you for your patience and advices. It is really an amazing project!