coatless / quarto-webr

Community developed Quarto Extension to Embed webR for HTML Documents, RevealJS, Websites, Blogs, and Books.
https://quarto-webr.thecoatlessprofessor.com/
394 stars 19 forks source link

[Bug]: Output being excessively truncated, causing gt to print incomplete tables #208

Closed erikvona closed 3 months ago

erikvona commented 5 months ago

Bug description

The output of chunks in WebR is being heavily truncated. This causes the package gt to malfunction, since a table contains so much CSS it is pretty much always truncated

Steps to reproduce

```{webr-r}
#| results: asis
webr::install("gt")
gt::gt(mtcars) |> print(view = FALSE)
Expected: The full table is printed. Actual:  a warning is printed (Warning: printing of extremely long output is truncated) and only the table headers are printed.

This can be ameliorated by chunking the output, e.g.: 

````{qmd}
```{webr-r}
#| results: asis
webr::install("gt")
fix_print <- function(characters, max_print = 100){
  i <- 1
  while(nchar(characters) >= i){
    cat(substring(characters, i, i + max_print ))
    i <- i + max_print + 1
  }
}
gt::gt(mtcars) |> gt::as_raw_html(inline_css = FALSE) |> fix_print()

I've tracked the error message to [this line](https://github.com/r-wasm/webr/blob/c07d8997ddbb58f63002e8d46792be54edcd134c/packages/webr/src/outputconnection.c#L101) in WebR, but the [WebR REPL](https://webr.r-wasm.org/latest/) does not produce this error and can produce the full output.

### Your environment

Online: on https://quarto-webr.thecoatlessprofessor.com/demos/qwebr-code-cell-options.html#results-option there's a chunk with `#| results: asis` which can be used to reproduce this behavior.

Also, Windows 10, R 4.4.0.

### Quarto check output

```bash
Quarto 1.5.43
[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.2.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.5.43
      Path: C:\Program Files\Quarto\bin
      CodePage: 1252

[>] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[>] Checking LaTeX....................OK
      Tex:  (not detected)

[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....OK
      Version: 3.9.6
      Path: C:/Python39/python.exe
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with py -m pip install jupyter

[>] Checking R installation...........OK
      Version: 4.3.2
      Path: C:/R/r_lang
      LibPaths:
        - C:/r-checkpoint/no-checkpoint
        - C:/R/library
      knitr: 1.45
      rmarkdown: 2.25

[>] Checking Knitr engine render......OK
coatless commented 5 months ago

@erikvona going to upstream a portion of the printing cut-off to the main webR repo. The difference with the webR REPL vs the quarto-webr code cell is we're using Shelter.captureR() instead of Console to obtain and process output.

The later portion regarding the asis is related to #166

coatless commented 5 months ago

Relevant ticket: https://github.com/r-wasm/webr/issues/434

coatless commented 5 months ago

George expanded the buffer in webR. So the latest version has been fixed. It'll propagate out in either v0.3.4/v0.4.0.