---
title: "slickR with Iframes"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{iframes}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup}
library(slickR)
```

## Iframes
  
Since the carousel can accept any html element we can place iframes in the carousel.
  
There are times when you may want to put in different DOMs rather than an image in slick. 

Using `slideType` you can specify which DOM is used in the slides. 
  
For example lets put the help Rd files from ggplot2 into a slider using the helper function `getHelp`.

__Dont forget to open the output to a browser to view the iframe contents__

### Function to fetch help files as HTML

```{r}

get_help <- function(fn,pkg){
 
  ff <- get('index.search',envir = asNamespace('utils'))(
    topic = fn, 
    paths = find.package(pkg),
    TRUE)
  
  path    <- dirname(ff)
  dirpath <- dirname(path)
  pkgname <- basename(dirpath)
  RdDB    <- file.path(path, pkgname)
  
  paste0(
    utils::capture.output({
      tools::Rd2HTML(
        Rd = get('fetchRdDB', envir = asNamespace('tools'))(RdDB, basename(ff))
      )
    }),
  collapse='\n')
  
}

```

### Retrieve help from `stats` 

```{r}

help_files <- lapply(
    ls("package:stats",pattern = '^r')[-1],
    get_help,
    pkg = 'stats')

```

### Create IFRAME slick

```{r}

slickR::slickR(help_files,
               slideType = 'iframe',
               height = 400,
               width='95%') + 
  settings(dots  = TRUE, 
           slidesToShow   = 2, 
           slidesToScroll = 2)
```