问题
I'm trying to save a heatmap produced by d3heatmap to a pdf file, but the file is always damaged.
library(d3heatmap)
pdf(file="heat.pdf")
d3heatmap(mtcars, scale = "column", colors = "Spectral")
dev.off()
I suspect the challenge is "this is an R package that implements a heatmap htmlwidget." However, I figured I could still capture the image produced because "Like any htmlwidget, you can visualize a d3 heatmap directly from the R console."
I looked at the two output functions in the package, renderD3heatmap
and d3heatmapOutput
, but I don't think either one gets me where I want to go.
Update
I followed @hrbrmstr's advice to look into knitr
and webshot
. See this answer about how to get them to play nice. Here's my latest attempt to produce an image file. I think I'm on the right track with screenshot.opts, but I'm getting a file about a bad connection.
---
title: "Untitled"
output: pdf_document
---
```{r, setup}
library(d3heatmap)
library(knitr) # dev't version knitr_1.12.22 (also dev't version of webshot 0.3)
```
```{r, screenshot.opts=list(file="webshot.png", cliprect="viewport", selector = NULL)}
d3heatmap(mtcars, scale = "column", colors = "Spectral")
```
来源:https://stackoverflow.com/questions/36041601/save-heatmap-generated-by-d3heatmap