save heatmap generated by d3heatmap

↘锁芯ラ 提交于 2020-01-24 10:54:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!