how to render output of wordcloud2 in RMarkdown

1.8k views Asked by At

How can I make sure that the output of wordcloud2::wordcloud2() appears in my RMarkdown (HTML) document?

It renders fine in RStudio, including in the preview of the RMarkdown document, but when I upload it to my netlify site with blogdown, it doesn't show (see here, bottom of the post). Any ideas?

Edit: here's the code I'm using. Like I said, it works perfectly in RStudio, just not on the website itself.

library(tidyRSS)

five38 <- tidyfeed("http://fivethirtyeight.com/all/feed")
library(wordcloud2)

topics <- five38$item_category1 %>% append(five38$item_category2) %>% 
  append(five38$item_category3) %>% 
  append(five38$item_category4) %>% 
  append(five38$item_category5)

Topics <- data_frame(
  words = topics
) %>% 
  filter(!is.na(words)) %>% 
  group_by(words) %>% 
  tally()

wordcloud2(Topics)
1

There are 1 answers

0
Heaven Zone On BEST ANSWER
```{r}
library(htmlwidgets)
install.packages("webshot")
webshot::install_phantomjs()
library(wordcloud2)
hw = wordcloud2(demoFreq,size = 3)
saveWidget(hw,"1.html",selfcontained = F)
webshot::webshot("1.html","1.png",vwidth = 700, vheight = 500, delay =10)
```
![](1.png)

ok, i found this way to solve this problem from the author of wordcloud2.