Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wordcloud failing in Rmarkdown tabsets #65

Open
QuentinB02 opened this issue May 23, 2019 · 10 comments
Open

Wordcloud failing in Rmarkdown tabsets #65

QuentinB02 opened this issue May 23, 2019 · 10 comments

Comments

@QuentinB02
Copy link

Hello,

I am facing what seems like a bug while using the worcloud2 package with Rmarkdown : displaying one or multiple workclouds on the same page works fine, as long as I do not make use of tabs (namely tabsetPanel from Shiny). Specifically any wordcloud that's not on the first tab will not be shown.

Here is a reproducible Rmd example (without header formatting, but I also attached the Rmd version to this issue) :


title: "Wordcloud tabset error in Rmd"
output: html_document

library(wordcloud2)
library(shiny)
wordcloud = wordcloud2::wordcloud2(data.frame(word = c("foo", 
                                                       "bar", 
                                                       "foobar"),
                                              n = c(15, 
                                                    35, 
                                                    50)))
tabsetPanel(
  tabPanel("test", wordcloud),
  tabPanel("test2", wordcloud)
)

wordcloud_tabset_error.zip

Upon knitting, the first wordcloud is showing, but not the second one...
Any idea why that might be? Thanks in advance for any help on the matter, and thanks for all the amazing work on this package.

PS : I installed the latest package version from Github, not the one on CRAN

@samuelhuerga
Copy link

Happens the same here.

If I use two wordclouds in an rmd knitted to HTML, only the first one is shown.

@gaospecial
Copy link

Happens the same here.

If I use two wordclouds in an rmd knitted to HTML, only the first one is shown.

Same here.

@gaospecial
Copy link

gaospecial commented Nov 21, 2019

here I have a alternative solution.

Use the following function.

#' Webshot a widget and place it in place with markdown syntax
#'
#' @param widget a html widget, i.e. generated by wordcloud2 pacakge
#' @param path figure webshot storage place
#'
#' @return
#' @export
#'
#' @examples
markdown_widget <- function(widget,path=getwd(),filename="file.png"){
  require(htmlwidgets)
  require(webshot)
  saveWidget(widget,"tmp.html",selfcontained = F)
  file <- paste(path,filename,sep = "/")
  webshot("tmp.html",file,delay = 5,vwidth = 1024,vheight = 768)
  file.remove("tmp.html")
  paste0("![",file,"](",file,")\n\n") %>% cat()
}

when in markdown file, insert a chunk like this:

```{r results="asis"}
widget <- wordcloud2(...)
markdown_widget(widget,path=".",filename="wordcloud.png")
```

then in your markdown file, the figure will finally show up.

@gaospecial
Copy link

gaospecial commented Feb 4, 2020

Hi @samuelhuerga,

I found a way to slove my problem.

Just install my fork by devtools::install_github("gaospecial/wordcloud2"), and then it works.

The following test code

library(wordcloud2)
wordcloud2(data = head(demoFreq,3))
wordcloud2(head(demoFreq,3), color = "random-light", backgroundColor = "grey")
wordcloud2(head(demoFreq,6), color = "random-light", backgroundColor = "white")

will give the result:

image

I don't know why it works, as I just update the wordcloud2.js library to the latest version.

May this can be helpful.

@martinctc
Copy link

Thanks Gao! I found that your solution (using your fork) worked for me in a 'standard' RMarkdown document, but not when used with tabset within flexdashboard. Here's a repo I quickly created producing the example:

https://github.com/martinctc/wordcloud2-test

Any idea if this is more an issue with flexdashboard perhaps?

@daczarne
Copy link

I just used @gaospecial 's version and it rendered both my wordcloud2s while using flexdashboard. Belows my session information

> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS

Matrix products: default
BLAS:   /opt/R/3.6.3/lib/R/lib/libRblas.so
LAPACK: /opt/R/3.6.3/lib/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
 [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C           LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

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

other attached packages:
[1] dplyr_1.0.2       data.table_1.13.0 dtplyr_1.0.1      magrittr_1.5      lubridate_1.7.9  

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5          here_0.1            tidyr_1.1.0         prettyunits_1.1.1   ps_1.3.4            assertthat_0.2.1    rprojroot_1.3-2    
 [8] digest_0.6.25       packrat_0.5.0       R6_2.4.1            backports_1.1.8     evaluate_0.14       httr_1.4.1          ggplot2_3.3.2      
[15] pillar_1.4.6        rlang_0.4.7         lazyeval_0.2.2      curl_4.3            rstudioapi_0.11     callr_3.4.3         rmarkdown_2.3      
[22] desc_1.2.0          devtools_2.3.1      flexdashboard_0.5.2 readr_1.3.1         stringr_1.4.0       htmlwidgets_1.5.1   munsell_0.5.0      
[29] compiler_3.6.3      xfun_0.16           pkgconfig_2.0.3     pkgbuild_1.1.0      htmltools_0.5.0     tidyselect_1.1.0    tibble_3.0.3       
[36] fansi_0.4.1         viridisLite_0.3.0   crayon_1.3.4        withr_2.2.0         grid_3.6.3          jsonlite_1.7.0      formattable_0.2.0.1
[43] gtable_0.3.0        lifecycle_0.2.0     scales_1.1.1        cli_2.0.2           stringi_1.4.6       fs_1.5.0            remotes_2.2.0      
[50] testthat_2.3.2      ellipsis_0.3.1      generics_0.0.2      vctrs_0.3.2         forcats_0.5.0       tools_3.6.3         glue_1.4.1         
[57] purrr_0.3.4         hms_0.5.3           crosstalk_1.1.0.1   processx_3.4.3      pkgload_1.1.0       yaml_2.2.1          colorspace_1.4-1   
[64] sessioninfo_1.1.1   memoise_1.1.0       plotly_4.9.2.1      wordcloud2_0.2.3    knitr_1.29          usethis_1.6.1

@davidika
Copy link

davidika commented Sep 2, 2020

thank you @gaospecial !

I wonder what is causing the issue. Outdated package installing via "wordcloud2" directly?

@eimennin
Copy link

eimennin commented Sep 2, 2021

Thanks, @gaospecial I have had this problem for years!

Does anyone know why lettercloud() doesn't work?

@gaospecial
Copy link

thank you @gaospecial !

I wonder what is causing the issue. Outdated package installing via "wordcloud2" directly?

May be the backend wordcloud javascript has bug, as its version is very low.

@jrtran
Copy link

jrtran commented Sep 24, 2021

Thanks Gao! I found that your solution (using your fork) worked for me in a 'standard' RMarkdown document, but not when used with tabset within flexdashboard. Here's a repo I quickly created producing the example:

https://github.com/martinctc/wordcloud2-test

Any idea if this is more an issue with flexdashboard perhaps?

A bit old, but for @martinctc: something that got all of the wordclouds to show up for me was appending {.active} after each sub-header (e.g., ### Tab 1 {.active}.

Tab 1
Tab 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants