Lchiffon / wordcloud2

R interface to wordcloud for data visualization.
397 stars 113 forks source link

wordcloud and htmlwidgets::saveWidget #11

Closed davidgohel closed 7 years ago

davidgohel commented 7 years ago

Thanks for your package, it's very useful.

I met an issue when using htmlwidgets::saveWidget. Could you help on that?

library(wordcloud2)
xx <- wordcloud2(data = demoFreq)
htmlwidgets::saveWidget(widget = xx, file = "test.html", selfcontained = TRUE)

When opening the file test.html, nothing is displayed. An javascript error can be read in the js console: Uncaught TypeError: canvas.getBoundingClientRect is not a function(…)

> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)

locale:
[1] fr_FR.UTF-8/fr_FR.UTF-8/fr_FR.UTF-8/C/fr_FR.UTF-8/fr_FR.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] wordcloud2_0.2.0 RProtoBuf_0.4.7 

loaded via a namespace (and not attached):
 [1] htmlwidgets_0.7 htmltools_0.3.5 tools_3.3.1     base64enc_0.1-3 RCurl_1.95-4.8  yaml_2.1.13    
 [7] Rcpp_0.12.7     jsonlite_1.1    digest_0.6.10   bitops_1.0-6

KR, David

Lchiffon commented 7 years ago

I've found this problem, try this:

htmlwidgets::saveWidget(widget = xx, file = "test.html", selfcontained = FALSE)

Looking forward to opening a issue in htmlWidges ...

davidgohel commented 7 years ago

Yes, if using selfcontained = FALSE I have what's expected.

davidgohel commented 7 years ago

Hi,

Is that a wontfix? We wanted self-contained files because that was the only format supported on a portal (MS sharepoint).

Lchiffon commented 7 years ago

Try this function:

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")

pandoc leave some strange output for self-contained html.