Closed nebuzoltanszuhai closed 7 years ago
Could you please leave your codes here?
Just using a small data like demoFreq
library(wordcloud2)
library(htmlwidgets)
m <- wordcloud2::wordcloud2(wordcloud2::demoFreq)
htmlwidgets::saveWidget(m, file = "wordcloud2.html", selfcontained = TRUE)
The html itself saved, opening the html in a browser gives a "blank" page, viewing it with source view, you see this error:
TypeError: canvas.getBoundingClientRect is not a function. (In 'canvas.getBoundingClientRect()', 'canvas.getBoundingClientRect' is undefined)
htmlwidgets: 0.8
wordcloud2: 0.2.0
Tried with Safari and Chrome in MacOs, same behavior. In RStudio this looks ok:
wordcloud2::wordcloud2(wordcloud2::demoFreq)
Try this simple function to fix it, it is a problem caused by strange DOM, not because of wordcloud2, but pandoc...
simpleFix = function(inputFile, outputFile){
a = readLines(inputFile)
output = paste(a, collapse = "\n")
output = gsub(">\n\n</div>","></div>",output)
writeLines(output, outputFile)
invisible(NULL)
}
library(wordcloud2)
library(htmlwidgets)
m <- wordcloud2::wordcloud2(wordcloud2::demoFreq)
htmlwidgets::saveWidget(m, file = "wordcloud2.html", selfcontained = TRUE)
simpleFix("wordcloud2.html", "wordcloud2.html")
Works perfectly, thanks!
I tried to save the widget with the self-contained option, that does not work. There is nothing fancy in the frequency table I use, normal English words. Would be great if you could fix it. (Where I would like to use the widget, there is no option for using the non self-contained form of it.)