Title: | 'Htmlwidgets' in Responsive 'iframes' |
---|---|
Description: | Provides two functions 'frameableWidget()', and 'frameWidget()'. The 'frameableWidget()' is used to add extra code to a 'htmlwidget' which allows is to be rendered correctly inside a responsive 'iframe'. The 'frameWidget()' is a 'htmlwidget' which displays content of another 'htmlwidget' inside a responsive 'iframe'. These functions allow for easier embedding of 'htmlwidgets' in content management systems such as 'wordpress', 'blogger' etc. They also allow for separation of widget content from main HTML content where CSS of the main HTML could interfere with the widget. |
Authors: | Bhaskar Karambelkar [aut, cre], Yihui Xie [ctb], NPR Visual Team [ctb, cph] (pym.js JavaScript library), Bjørn Klinggaard [ctb, cph] (bLazy.js JavaScript library) |
Maintainer: | Bhaskar Karambelkar <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.1 |
Built: | 2024-11-11 02:58:22 UTC |
Source: | https://github.com/trafficonese/widgetframe |
This function augments a htmlwidget so that when saved, the resulting HTML document can be rendered correctly inside a responsive iframe (created using Pym.js) of another HTML document.
frameableWidget(widget, renderCallback = NULL)
frameableWidget(widget, renderCallback = NULL)
widget |
The widget to add the pymjs code to. |
renderCallback |
An optional Javascript function wrapped in |
Generate your htmlwidget in the normal way and then call this function
passing in your widget. Then call saveWidget()
and
the saved HTML file is now embeddable inside a Pym.js iframe of another HTML document.
See Pym.js documentation on how to
create an HTML document with a responsive iframe.
frameWidget()
.
## Not run: library(leaflet) l <- leaflet() %>% addTiles() %>% setView(0,0,1) htmlwidgets::saveWidget( widgetframe::frameableWidget(l),'some-directory-on-your-disk') ## End(Not run)
## Not run: library(leaflet) l <- leaflet() %>% addTiles() %>% setView(0,0,1) htmlwidgets::saveWidget( widgetframe::frameableWidget(l),'some-directory-on-your-disk') ## End(Not run)
Taken from Pym.js Documentation. In addition also check out the iframe documentation.
frameOptions(xdomain = "*", title = NULL, name = NULL, id = NULL, allowfullscreen = FALSE, sandbox = NULL, lazyload = FALSE)
frameOptions(xdomain = "*", title = NULL, name = NULL, id = NULL, allowfullscreen = FALSE, sandbox = NULL, lazyload = FALSE)
xdomain |
xdomain to validate messages received. |
title |
If passed it will be assigned to the iframe title attribute. |
name |
If passed it will be assigned to the iframe name attribute. |
id |
If passed it will be assigned to the iframe id attribute. |
allowfullscreen |
If TRUE it will set the iframe allowfullscreen attribute to true. |
sandbox |
If passed it will be assigned to the iframe sandbox attribute. |
lazyload |
If TRUE the child widget is lazy loaded using bLazy.js. |
Uses Pym.js. Pym.js embeds and resizes an iframe responsively (width and height) within its parent container. It also bypasses the usual cross-domain issues.
frameWidget(targetWidget, width = "100%", height = NULL, elementId = NULL, options = frameOptions())
frameWidget(targetWidget, width = "100%", height = NULL, elementId = NULL, options = frameOptions())
targetWidget |
The widget to embed inside an iframe. |
width |
Defaults to 100 100, 200 (in pixel). This will override the width of the enclosed widget. |
height |
Defaults to NULL. You can either specify '10 100, 200 (in pixel). This will override the height of the enclosed widget. |
elementId |
The element ID of the parent widget. |
options |
Options for the iframe. |
This widget can be used in places where a HTML page's CSS rules or Javascript code can cause issues in a widget. Wrapping your widgets this way allows for the widget code to be unaffected by the parent HTML's CSS/JS. The target widget is conveniently displaed in a responsive iframe and not subject to parent HTML's CSS/JS.
frameOptions()
.
## Not run: l <- leaflet() %>% addTiles() %>% setView(0,0,1) frameWidget(l) ## End(Not run)
## Not run: l <- leaflet() %>% addTiles() %>% setView(0,0,1) frameWidget(l) ## End(Not run)
Similar to saveWidget()
with the addition
that both the parent widget and the enclosed child widget are saved to two different HTML files.
saveWidgetframe(widget, file, selfcontained = FALSE, libdir = NULL, background = "white", knitrOptions = list())
saveWidgetframe(widget, file, selfcontained = FALSE, libdir = NULL, background = "white", knitrOptions = list())
widget |
widgetframe to save |
file |
File to save the parent widget into. The child widget will be saved to 'basename(file)_widget/index.html'. |
selfcontained |
Whether to save the parent and child HTMLs as a single self-contained files. WARNING: Setting this option to true will still result in two HTMLs, one for the parent and another for the child widget (with external resources base64 encoded), or files with external resources placed in an adjacent directory. |
libdir |
Directory to copy HTML dependencies into (defaults to filename_files). |
background |
Text string giving the html background color of the widget. Defaults to white. |
knitrOptions |
A list of knitr chunk options. |
This package provides two functions frameableWidget
, and frameWidget
.
The frameableWidget
is used to add extra code to a htmlwidget which
allows is to be rendered correctly inside a responsive iframe.
The frameWidget
is a htmlwidget which displays content of another
htmlwidget inside a responsive iframe.
Output and render functions for using widgetframe within Shiny applications and interactive Rmd documents.
widgetframeOutput(outputId, width = "100%", height = "400px") renderWidgetframe(expr, env = parent.frame(), quoted = FALSE)
widgetframeOutput(outputId, width = "100%", height = "400px") renderWidgetframe(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a widgetframe |
env |
The environment in which to evaluate |
quoted |
Is |