Hot to save html file only from R and htmlwidgets?

2.5k views Asked by At

I an using R to draw heatmap. Heatmaply and htmlwidget were installed. Fox example i exec following code:

library("htmlwidgets")
library("heatmaply")
heatmaply(mtcars) %>% saveWidget(file="test.html")

This always generate a test.html file and a test_files folder, but i want the test.html only. I try saveWidget(file="test.html",,selfcontained=TRUE). This just place the js library in the test.html, making test.html too big.

2

There are 2 answers

2
Julian Zucker On

Use self-contained=FALSE to create plain HTML and a seperate folder, then use system to remove that folder:

heatmaply(mtcars) %>% 
  saveWidget(file="test.html", selfcontained = FALSE)
system('rm -r test_files')

Just be careful you don't have a folder named x_files, where x is the name of your plot output!

1
Tal Galili On

A simpler solution is available in the recent version of heatmaply, simply use:

library("heatmaply")
heatmaply(mtcars, file="test.html")