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

Make it easier to render a tag as an iframe #365

Open
cpsievert opened this issue Feb 10, 2023 · 1 comment
Open

Make it easier to render a tag as an iframe #365

cpsievert opened this issue Feb 10, 2023 · 1 comment

Comments

@cpsievert
Copy link
Collaborator

cpsievert commented Feb 10, 2023

Currently you need to save_html(), then tags$iframe(), and take care to mount the right directories. It'd be neat if you could just mark a tag with something like asIFrame() and it just prints sensibly (similar to {widgetframe}, which is now deprecated, but works on any tag and in any context).

As a first pass on this, it might make sense to use an approach similar to https://github.com/jcheng5/shadowdom (i.e., leverage web components to transform the (document-ified) tag into an iframe on the client and also put it under a personal repo until we have full confidence in it)

@cpsievert
Copy link
Collaborator Author

cpsievert commented Feb 13, 2023

FWIW, here's a decent knitr-based solution.

```{r setup, include=FALSE}
library(knitr)
library(htmltools)

render_as_iframe <- function(x, options, ...) {
  lbl <- opts_current$get("label")
  if (!dir.exists(lbl)) {
    dir.create(lbl)
  }
  file <- file.path(lbl, paste0(lbl, ".html"))
  tryCatch(
    save_html(x, file), 
    error = function(e) {
      stop("Don't know how to render ", class(x)[[1]], " as an <iframe>")
    }
  )
  include_url(file)
}
```


```{r plotly, render=render_as_iframe, out.width="100%", out.extra='scrolling="no" seamless="seamless" frameBorder="0"'}
plotly::plot_ly()
```

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

1 participant