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")
```
knitr
. It has functionality from the newwebshot
package to facilitate this. – Billingsleywebshot
function in the development version ofknitr
, so I downloaded thewebshot
package directly. Seems like it wants me to feed it a URL. Any pointers to examples of folks using this package (or from within knitr if I'm doing something wrong) to capture this widget? – Katabolismwebshot
function in the development version ofknitr
, but maybe I shouldn't have. going to play around with this. – Katabolismwebshot::install_phantomjs()
. i get the message:phantomjs.exe has been installed to /Users/username/Library/Application Support/PhantomJS
however when i run, i get the error thatsh: ~/Library/Application Support/PhantomJS/phantomjs: No such file or directory
. i think that i need to update the path, but i'm not sure how. – Katabolism