Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webr support for {gt} package #431

Closed
rainer-rq-koelle opened this issue Jun 1, 2024 · 4 comments
Closed

webr support for {gt} package #431

rainer-rq-koelle opened this issue Jun 1, 2024 · 4 comments

Comments

@rainer-rq-koelle
Copy link

rainer-rq-koelle commented Jun 1, 2024

Congrats! I am just fascinated by what can be done with wasm/webr. I embrace tinkering with it and see a huge potential for teaching/demoing "many things R coding" related. However, I admit that the "magic of its working" is outside my comprehension.

Following some of the tutorials/introductory material, I wanted to use webr to showcase {gt}.
When setting up the Quarto document and rendering it, I hoped that the following would work like a charm. I have failed to find any meaningful pointer(s).

Question on stackoverflow: https://stackoverflow.com/questions/78534930/webr-and-gt-throws-error-error-browser-must-be-a-non-empty-character-stri

The error message thrown from the web-r chunk output reads: Error: 'browser' must be a non-empty character string

Quarto yaml:

engine: knitr
filters:

  • webr
    webr:
    packages: ['dplyr','gt']

And then let's trial {gt}

my_tbl <- mtcars[1:10,] |> tibble()

my_tbl |> gt()
Screenshot 2024-06-01 at 09 21 34

Calling ?gt in the webr-container on a rendered webpage results in the standard (embedded) help page for {gt}. Thus, the package {gt} appears to be loaded and available in the {webr} session.

Could someone put me on the right track? Thanks.

@timelyportfolio
Copy link

timelyportfolio commented Jun 2, 2024

@rainer-rq-koelle I am not on the official team, but I do have some experience with html and R, so I'll try to chime in with some hopefully helpful context. This issue relates to the fact that webr does not have a browseURL equivalent viewer (such as RStudio Viewer tab in RStudio or chrome/edge/firefox).

The gt:::print.gt_tbl method in an interactive session will effectively create an html file which then opens with browseURL except we do not have a browser in webr. For instance, htmlwidgets use a very similar mechanism, and these also will not work in a webr Quarto context failing with this same error.

This is a challenging issue, but there might be some hope. I started to explore how we might resolve with htmlwidgets in this post, but unfortunately this is not automated and requires special effort customized to each htmlwidget. Using an example from gt we can see that we ultimately can get the html with view=FALSE (similar to producing gt in Rmd or Quarto without webr).

gt:::print.gt_tbl(exibble |> gt(), view = FALSE)

image

webr just doesn't know what to do with an html file. iframe might be a solution but also can be very clunky.

@georgestagg
Copy link
Member

@timelyportfolio is correct. Unfortunately webR does not currently support displaying htmltools or htmlwidgets output in the containing web page. AFAIK this is unsupported in the community-driven quarto-webr extension (https://github.com/coatless/quarto-webr) right now too, though it might be on their radar for future work.


Saying that... I am right now working on significantly improving webR and Quarto integration, including support for displaying HTML widgets from webR in Quarto documents, without any of the overhead work mentioned above. Here is a preview:

Screenshot 2024-06-02 at 18 10 30

This new framework is not yet ready for release, but I'll be continuing to work on it and will release more information about it in the coming weeks.

@timelyportfolio
Copy link

@georgestagg this looks amazing!! Please let me know how I can help. I am more than happy to support in any way possible.

@georgestagg
Copy link
Member

Closing as this should now work in the REPL. The new extension I mention above for use in Quarto should hopefully be available by the end of this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants