1

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.

Robin
  • 43
  • 8

2 Answers2

2

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!

Julian Zucker
  • 564
  • 4
  • 13
  • 1
    This lost the whole purpose of `selfcontatined` and the library folder and is not a solution. The html may not work if copied to other place. – dracodoc Jan 11 '18 at 15:06
  • Can you please take a look at this question? https://stackoverflow.com/questions/65606653/r-saving-multiple-html-widgets-together thanks! – stats_noob Jan 07 '21 at 05:48
2

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

library("heatmaply")
heatmaply(mtcars, file="test.html")
Tal Galili
  • 24,605
  • 44
  • 129
  • 187
  • Can you please take a look at this question? https://stackoverflow.com/questions/65606653/r-saving-multiple-html-widgets-together thanks! – stats_noob Jan 07 '21 at 05:48