coatless / quarto-webr

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

[Feature]: Customize data.frame output #207

Open andrewheiss opened 1 month ago

andrewheiss commented 1 month ago

Feature Description

In {learnr}, the results from printing data.frame output are shown as paged tables by default (using rmarkdown::paged_table(), I think)

Screenshot 2024-05-22 at 16 40 50

 

I've tried to recreate something similar with {quarto-webr}, but something along the way isn't working, and I'm not sure what.

---
title: "Testing"
format: html
engine: knitr
filters:
  - webr
webr:
  packages:
    - rmarkdown
---

```{webr-r}
#| context: setup
print.data.frame <- function(x, ...) {
  cat("This should be paged?\n")
  rmarkdown::paged_table(x)
}
# Implicit print doesn't use print.data.frame()
mtcars
# Explicit print does use print.data.frame(), but it's not paged
print(mtcars)


<img width="655" alt="image" src="https://github.com/coatless/quarto-webr/assets/73663/288e3a57-dc8c-4835-81e9-c6569b127e3c">

<img width="657" alt="image" src="https://github.com/coatless/quarto-webr/assets/73663/4dba0c5a-8594-45cc-acfc-b6f410dbd1fa">

&nbsp;

I don't know if it's currently possible to do this with {quarto-webr}, but it would be nice!
coatless commented 1 month ago

The short gist: This isn't likely to happen anytime soon.

The longer gist:

I think some extra markup is happening with the rmarkdown::print.page_df() and knitr::asis_output() functions that assumes rendering from a static source.

Other hiccups relate to the meta dependencies being unable to be added to the document as we're past the render stage. Though, I think the dependencies themselves assume that the document is opened with the data embedded as the output from rmarkdown::paged_html_table() consists of a div with a script tag containing dumped data.

On {quarto-webr}'s end, we'd need the results: asis mode to avoid marking up content instead of only allowing it to pass through. c.f. #166

andrewheiss commented 1 month ago

Ok cool cool, I'll just live with the default data.frame and tibble-based print()s. In my actual use case, I ended up showing the data frame that learners are working with using a separate, normal {r} chunk with a paged data frame, so they can still navigate the larger dataset.