Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在r标记html输出中嵌入d3js/html小部件图_R - Fatal编程技术网

如何在r标记html输出中嵌入d3js/html小部件图

如何在r标记html输出中嵌入d3js/html小部件图,r,R,我遇到了一个漂亮的R代码,是R()的htmlwidget格式的d3\u爆炸式\u箱线图——如果我们点击箱线图,箱线图就会分解成散点图——真的很酷 代码: 问题是,在运行代码之后,我们在R studio图形查看器窗格中获得了交互式箱线图,但当您将其编织到R markdown html文档中时,图形根本不可见……它只是意味着我必须以某种方式呈现html小部件并嵌入到html文档中,我不知道怎么做……我搜索了解决方案,但很遗憾……我刚刚在包中添加了一个小插曲,以演示如何在rmarkdown文档中使用e

我遇到了一个漂亮的R代码,是R()的htmlwidget格式的d3\u爆炸式\u箱线图——如果我们点击箱线图,箱线图就会分解成散点图——真的很酷

代码:


问题是,在运行代码之后,我们在R studio图形查看器窗格中获得了交互式箱线图,但当您将其编织到R markdown html文档中时,图形根本不可见……它只是意味着我必须以某种方式呈现html小部件并嵌入到html文档中,我不知道怎么做……我搜索了解决方案,但很遗憾……

我刚刚在包中添加了一个小插曲,以演示如何在
rmarkdown
文档中使用
explodingboxplotR
。代码如下所示

---
title: "Intro to Exploding Boxplots"
author: "Kenton Russell"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Intro to Exploding Boxplots}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

[Exploding Boxplots](https://github.com/mcaule/d3_exploding_boxplot) provide a fun and useful look at the distribution of data.  This `R` package [`explodingboxplotR`](https://github.com/timelyportfolio/explodingboxplotR) uses `htmlwidgets` to allow us to incorporate these exploding boxplots in all R contexts, such as `rmarkdown`, `Shiny`, the `R` console, and in a web browser.

### Install

`explodingboxplotR` is not on CRAN, so we'll use `devtools::install_github` to install.

```{r eval = FALSE}
devtools::install_github("timelyportfolio/explodingboxplotR")
```

### Use

```{r}
library(explodingboxplotR)

# use this to replicate
#   from ?boxplot
#boxplot(count ~ spray, data = InsectSprays, col = "lightgray")

exploding_boxplot(
  data.frame(
    rowname = rownames(InsectSprays),
    InsectSprays,
    stringsAsFactors = FALSE
  ),
  y = "count",
  group = "spray",
  color = "spray",
  label = "rowname"
)
```

We get some options to customize our exploding boxplots.  Let's look at these in the next example.

```{r}
# demonstrate all of the options
#  xlab does not work
#  filed issue on source repo
exploding_boxplot(
  data.frame(
    rowname = rownames(InsectSprays),
    InsectSprays,
    stringsAsFactors = FALSE
  ),
  y = "count",
  group = "spray",
  color = "spray",
  label = "rowname",
  iqr = 2,
  margin = list(bottom = 50, left = 30, top = 20, right = 20),
  xlab = "Spray Type",
  ylab = "Count Provided"
)
```
此工作版本的
devtools::session_info()

Session info -------------------------------------------------------------------
 setting  value                       
 version  R version 3.2.2 (2015-08-14)
 system   x86_64, mingw32             
 ui       RStudio (0.99.875)          
 language (EN)                        
 collate  English_United States.1252  
 tz       America/Chicago             
 date     2016-02-03                  

Packages -----------------------------------------------------------------------
 package     * version     date       source                              
 devtools      1.9.1.9000  2015-10-24 local                               
 digest        0.6.9       2016-01-08 CRAN (R 3.2.3)                      
 DT            0.0.20      2015-03-12 Github (rstudio/DT@e7130f7)         
 htmltools     0.3         2015-12-29 CRAN (R 3.2.3)                      
 htmlwidgets   0.5.2       2016-01-29 local                               
 httpuv        1.3.3       2015-08-04 CRAN (R 3.2.2)                      
 jsonlite      0.9.19.9000 2015-12-01 Github (jeroenooms/jsonlite@2158a16)
 knitr         1.11        2015-08-14 CRAN (R 3.2.2)                      
 magrittr      1.5         2015-04-17 Github (smbache/magrittr@89f143d)   
 memoise       0.2.1       2014-04-22 CRAN (R 3.1.0)                      
 mime          0.4         2015-09-03 CRAN (R 3.2.2)                      
 R6            2.1.1       2015-08-19 CRAN (R 3.2.2)                      
 Rcpp          0.12.3      2016-01-10 CRAN (R 3.2.3)                      
 rmarkdown     0.9.2       2016-01-01 CRAN (R 3.2.2)                      
 shiny       * 0.12.2      2015-08-05 CRAN (R 3.2.3)                      
 xtable        1.7-4       2014-09-12 CRAN (R 3.1.2)                      
 yaml          2.1.13      2014-06-12 CRAN (R 3.1.3) 

当我将爆炸的箱线图放入RMarkdown演示文稿并编织时,它们对我的渲染是正确的。你能在不起作用的地方发布一个可复制的RMarkdown文档吗?你有最新版本的
htmlwidgets
RMarkdown
?这些软件包的发展非常迅速,所以我猜应该是过时的软件包。正如马特所建议的,如果你能发布你的
rmarkdown
代码或错误的结果,我相信我们可以帮助解决问题。
Session info -------------------------------------------------------------------
 setting  value                       
 version  R version 3.2.2 (2015-08-14)
 system   x86_64, mingw32             
 ui       RStudio (0.99.875)          
 language (EN)                        
 collate  English_United States.1252  
 tz       America/Chicago             
 date     2016-02-03                  

Packages -----------------------------------------------------------------------
 package     * version     date       source                              
 devtools      1.9.1.9000  2015-10-24 local                               
 digest        0.6.9       2016-01-08 CRAN (R 3.2.3)                      
 DT            0.0.20      2015-03-12 Github (rstudio/DT@e7130f7)         
 htmltools     0.3         2015-12-29 CRAN (R 3.2.3)                      
 htmlwidgets   0.5.2       2016-01-29 local                               
 httpuv        1.3.3       2015-08-04 CRAN (R 3.2.2)                      
 jsonlite      0.9.19.9000 2015-12-01 Github (jeroenooms/jsonlite@2158a16)
 knitr         1.11        2015-08-14 CRAN (R 3.2.2)                      
 magrittr      1.5         2015-04-17 Github (smbache/magrittr@89f143d)   
 memoise       0.2.1       2014-04-22 CRAN (R 3.1.0)                      
 mime          0.4         2015-09-03 CRAN (R 3.2.2)                      
 R6            2.1.1       2015-08-19 CRAN (R 3.2.2)                      
 Rcpp          0.12.3      2016-01-10 CRAN (R 3.2.3)                      
 rmarkdown     0.9.2       2016-01-01 CRAN (R 3.2.2)                      
 shiny       * 0.12.2      2015-08-05 CRAN (R 3.2.3)                      
 xtable        1.7-4       2014-09-12 CRAN (R 3.1.2)                      
 yaml          2.1.13      2014-06-12 CRAN (R 3.1.3)