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

`echo=false` seems to not hide the source code #62

Closed joelostblom closed 4 hours ago

joelostblom commented 6 days ago

It seems like specifying echo: false still includes the source code in the ouput document

```{webr}
#| echo: false

4 + 5
#| echo: false

4 + 5


![image](https://github.com/user-attachments/assets/d84c2ebc-5541-468b-9b92-fa5d12c64e41)
joelostblom commented 6 days ago

Interestingly if I set both edit: false and echo: false the code block is hidden as expected

andrewpbray commented 6 days ago

What is the behavior you'd like to see here? Just the output with no source code or webr UI (start over, run code buttons)?

georgestagg commented 6 days ago

I think the right behaviour here should be:

echo: false, edit: true: The code editor is shown, output is suppressed.

echo: false, edit: false: The source is shown as a fixed code block, output is suppressed.

echo: true, edit: true: (Default): The code editor is shown, output is shown.

echo: true, edit: false: The source is shown as a fixed code block, output is shown.

EDIT: I am confused, see below comments.

include: false: The code is executed in the Wasm engine but with no visual elements are shown on the page. edit and echo are ignored.

Happy to see any other thoughts or opinions on this behaviour. Notably, the current implementation does not act as above:

Currently, include: false visually behaves correctly but does not execute the source in the Wasm engine.

joelostblom commented 5 days ago

What is the behavior you'd like to see here? Just the output with no source code or webr UI (start over, run code buttons)?

I was expecting echo: false to suppress the entire input element and only show the output, so no buttons visible (similar to currently setting both edit: false and echo: false). To me, this would be the most similar to how echo: false currently works for regular quarto code blocks, but as long as there is an easy option to execute code in webassembly without showing it, I don't feel too strongly about which of the suggested approaches achieves that.

Happy to see any other thoughts or opinions on this behaviour.

Interesting that you mention that echo is used to suppress the output rather than the source code. Wouldn't this be what the output cell option is for?

include: false visually behaves correctly but does not execute the source in the Wasm engine.

Thanks for clarifying this; my expectation was also that these cells should be executed but couldn't figure out why they weren't when I tried it.

georgestagg commented 5 days ago

Interesting that you mention that echo is used to suppress the output rather than the source code. Wouldn't this be what the output cell option is for?

Oh shoot, looks like I had gotten myself quite confused when I wrote that comment! You’re right, output is controlled elsewhere.

Let’s try that again:

Hopefully that looks more reasonable!

joelostblom commented 5 days ago

That looks exactly like I would expect! I agree that the last option (echo: false, edit: true) doesn't really make sense and think that an error message is probably the clearest behavior in that case (but echo taking precedence would also be fine I think).

And having include: false being equivalent echo: false, edit: false, output: false makes sense to me as convenient shortcut (maybe explicitly mentioned in the api ref for clarity). I guess in this sense one could also think of include: false as a setup code block targeting the global env, so if there was an easy way to do that via setup, then maybe include is a redundant option (this is a minor comment though)?