我在dygraph()
中使用R markdown,当我工作时,我希望输出为html文档,让我喜欢dygraph()
的功能。但在工作结束时,我希望输出以pdf格式出现。因此,所有的音标都需要转换为.png。
---
title: "DygraphtoPng"
author: "Tibo"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Including Plots
```{r pressure, echo=FALSE}
require(dygraphs)
require(knitr)
require(webshot)
require(htmlwidgets)
if (`r output` == "html_document") {
dygraph(pressure)
} else {
dy <- dygraph(pressure)
}
```
我知道webshot()
软件包可以帮助您完成工作,但我不知道如何做?
答案 0 :(得分:0)
您可以根据自己的要求将扩展名修改为.pdf,.png,...
代码:
---
title: "DygraphtoPng"
author: "Tibo"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Including Plots
```{r pressure, echo=FALSE}
require(dygraphs)
require(knitr)
require(webshot)
require(htmlwidgets)
dy <- dygraph(pressure)
htmlwidgets::saveWidget(widget = dy, file = "dy.html")
webshot(url = "dy.html", file = "dy.pdf", delay = 1, zoom = 4, vheight = 500)