r - 使用 knitr 和 rgl 在 html 中包含 3D 交互式图形,在 word/pdf 中包含静态图形

标签 r knitr r-markdown rgl

按照这个问题( including a interactive 3D figure with knitr )和 Yihui 的这个例子( https://dl.dropboxusercontent.com/u/15335397/misc/webgl-rmd.html ),我可以使用 knitr 和 Rmarkdown 在 html 输出中包含一个 3D 交互式图形。但我想在 word/pdf 输出中包含一个静态数字。

是否有可能做到这一点?感谢您的任何建议。

我的 session 信息

> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252   
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rgl_0.95.1158 knitr_1.8    

loaded via a namespace (and not attached):
[1] evaluate_0.5.5 formatR_1.0    stringr_0.6.2  tools_3.1.1 

最佳答案

您可以使用以下设置根据输出格式进行切换

```{r, echo=FALSE}
out_type <- knitr::opts_knit$get("rmarkdown.pandoc.to")
keep <- if(out_type == "html") 'none' else 'last'
```


```{r chunk, echo=FALSE, fig.keep=keep}
plot(cars)
if(out_type == "html")
  cat("there goes fancy js code")
```

关于r - 使用 knitr 和 rgl 在 html 中包含 3D 交互式图形,在 word/pdf 中包含静态图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26965946/

相关文章:

r - 结合使用:= in data.表和paste()

R Notebook:并排放置 knitr::kable 表格?

r - 来自另一个 Rmd 中的 Rmd 文件的源代码

r - 如何在 rmarkdown 中打印 git 历史记录?

r - 如何在 rmarkdown 中显示带有结果 ='asis' 的格式化 R 输出

r - 如何检查矩阵的列是否遵循R中的预定顺序?

r - 使用 R dplyr 根据多个条件找到最佳组合

r - 具有 xyz 坐标的 3d 曲面图

RMarkdown/Knit : Hide code for Word document,,但 HTML 文档中的代码折叠

r - Knitr:内联文本的尾随零