Skip to content

Instantly share code, notes, and snippets.

@kbroman
Created February 23, 2015 15:07
Show Gist options
  • Save kbroman/a4b70d6eb582b9dc5141 to your computer and use it in GitHub Desktop.
Save kbroman/a4b70d6eb582b9dc5141 to your computer and use it in GitHub Desktop.
Problem with multiple htmlwidgets within an R Markdown document
---
title: "test qtlcharts"
author: "Karl Broman"
date: "February 23, 2015"
output: html_document
---
```{r load_lib}
library(devtools)
install_github("kbroman/qtlcharts", ref="htmlwidgets")
library(qtlcharts)
```
If I include multiple htmlwidgets charts within an R Markdown document,
only the resources for the first of them gets included.
For example, in the following, the two `iplot` examples will be shown,
but the `iplotPXG` example gives an error, `Uncaught ReferenceError: iplotPXG is not defined`.
If I move the `iplotPXG` chunk to before the `iplot` chunks, then
the `iplotPXG` example works, but the `iplot` examples give an error.
```{r iplot}
x <- rnorm(100)
grp <- sample(1:3, 100, replace=TRUE)
y <- x*grp + rnorm(100)
iplot(x, y, grp)
```
```{r iplot2}
iplot(y, x, grp)
```
```{r iplotPXG}
library(qtl)
data(hyper)
iplotPXG(hyper, "D4Mit164")
```
---
title: "test qtlcharts"
author: "Karl Broman"
date: "February 23, 2015"
output: html_document
---
```{r load_lib}
library(devtools)
install_github("kbroman/qtlcharts", ref="htmlwidgets")
library(qtlcharts)
```
If I include multiple htmlwidgets charts within an R Markdown document,
only the resources for the first of them gets included.
For example, in the following, the `iplotPXG` example will be shown,
but the `iplot` examples give an error.
If I move the `iplot` chunks to before the `iplotPXG` chunk, then
the `iplot` examples work, but the `iplotPXG` example give an error.
```{r iplotPXG}
library(qtl)
data(hyper)
iplotPXG(hyper, "D4Mit164")
```
```{r iplot}
x <- rnorm(100)
grp <- sample(1:3, 100, replace=TRUE)
y <- x*grp + rnorm(100)
iplot(x, y, grp)
```
```{r iplot2}
iplot(y, x, grp)
```
@timelyportfolio
Copy link

@kbroman
Copy link
Author

kbroman commented Feb 23, 2015

@timelyportfolio Thanks! That's understandable.

I guess the thing for me to do is to have a separate chunk of yaml for each of the basic bits, so it loads just what's necessary, and only once.

@timelyportfolio
Copy link

Yes, I think that is the best option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment