Created
February 23, 2015 15:07
-
-
Save kbroman/a4b70d6eb582b9dc5141 to your computer and use it in GitHub Desktop.
Problem with multiple htmlwidgets within an R Markdown document
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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") | |
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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) | |
``` |
An example for array of scripts is here https://github.com/htmlwidgets/iquiz/blob/master/inst/htmlwidgets/iquiz.yaml#L13.
@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.
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
yaml
reads name to determine diff, so the best way to handle would be to change the name, or ifqtlcharts
dependencies load all scripts with an array for script.is treated the same as
If you do not want an array of scripts so just load necessary dependencies, then this should make that happen.