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

A HTML widget viewer for the webR application, similar to browseURL() #449

Merged
merged 5 commits into from
Jun 24, 2024

Conversation

georgestagg
Copy link
Member

A function webr::viewer_install() is added to the webR support package. The function sets R up so as to generate an output message over the webR communication channel when a URL viewer is invoked using options("viewer").

Printing a HTML element or HTML widget in the webR application app now shows the resulting HTML output in an embedded viewer iframe, meaning packages like gt() can now work.

c.f. #295, #384, #431.


Screenshot 2024-06-24 at 09 30 48


Over the months I have considered several ways to handle requests to browseURL() from webR. After pondering for enough, in the interests of pragmatism this PR contains a "first-pass" approach that replaces relative JS and CSS sources in the output HTML file with content directly (encoded in base64) then displays the result in an iframe. With thanks to @timelyportfolio, as this is an improvement to their basic implementation method outlined here.

In the future, one or more of the following should be done, in order of "correctness":

  • Other types of relative URL in the output should be found and replaced.
  • Proper XML parsing should be done on the output, not regex replacement.
  • The output should instead be made self-contained in a more robost way, e.g. using Pandoc compiled for wasm.
  • The R object should instead be send to the main thread, not the HTML output. That way adding HTML dependencies to the page can be handled better in JavaScript.
  • A JS Service Worker should be started, serving the /tmp directory containing the HTML and support files. With this, relative URLs would "just work" without any modification.

@georgestagg georgestagg merged commit f2f079a into main Jun 24, 2024
4 checks passed
@georgestagg georgestagg deleted the widget-viewer branch June 24, 2024 12:16
@timelyportfolio
Copy link

@georgestagg Wow, this is absolutely amazing. I'll dive deeply over the week keeping in mind the list of "to-do". Let me know if there is anything I can do to help.

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

Successfully merging this pull request may close these issues.

2 participants