I use R markdown with dygraph(), when i am working i want the output to be an html document, allowing me to enjoy dygraph() features. But at the end of my work i want the ouput to be in a pdf. So all dygraphs need to be converted to .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)
}  
```
I know webshot()package can help doing it but i don't understand how?
                        
You could modify the extension based on your requirements as .pdf, .png, ...
The code:
The .png output