widgetframe

'Htmlwidgets' in Responsive 'iframes'


Keywords
htmlwidgets, rstats
License
MIT

Documentation

Project Status: Active – The project is being actively developed. Last-changedate License: MIT keybase verified Travis-CI Build Status AppVeyor Build Status minimal R version packageversion CRAN_Status_Badge

widgetframe: htmlwidgets inside responsive iframes.

The goal of widgetframe is to be able to embed widgets inside iframes using NPR's Pymjs library for responsive iframes.

This package provides two functions frameableWidget, and frameWidget. The frameableWidget is used to add extra code to a htmlwidget which allows it to be rendered inside a responsive iframe. The frameWidget returns a htmlwidget which displays content of another htmlwidget inside a responsive iframe.

Current Status


  • Does Not (Yet) Work With
    • Shiny

Installation

Release version

install.packages('widgetframe')

OR development version

if(!require(devtools)) {
  install.packages('devtools')
}
devtools::install_github('bhaskarvk/widgetframe')

Usage

frameableWidget function.

The frameableWidget function should be used when you need a HTML which can be embedded in a CMS system like WordPress/blogger or a static HTML website using the Pymjs library.

library(leaflet)
library(widgetframe)
l <- leaflet() %>% addTiles()
htmlwidgets::saveWidget(frameableWidget(l),'leaflet.html')

The resulting leaflet.html contains the necessary Pym.js Child initialization code and will work inside a regular iFrame or better yet a Pym.js responsive iFrame. It is expected that the site which is going to embed this widget's content has the necessary Pymjs Parent initialization code as described here.

frameWidget function

frameWidget function takes an existing htmlwidget as an argument and returns a new htmlwidget which when rendered, wraps the input htmlwdiget inside a responsive iFrame. This function can be used to knit htmlwidgets such that they are unaffected by the parent HTML file's CSS. This could be useful in bookdown or R Markdown Websites to embed widgets such that they are unaffected by the site's global CSS/JS.

You can use widgetFrame inside your R Markdowns as shown below.

```{r 01}
library(leaflet)
library(widgetframe)
l <- leaflet(height=300) %>% addTiles() %>% setView(0,0,1)
frameWidget(l)
```
```{r 02}
library(dygraphs)
ts <- dygraph(nhtemp, main = "New Haven Temperatures",
              height=250, width='95%')
frameWidget(ts)
```

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.