jbkunst / d3wordcloud

:cloud: htmlwidgets for D3js Word Cloud Layout
http://rpubs.com/jbkunst/133106
66 stars 15 forks source link

Unexpected Behavior (overlap and not disappear) #27

Open systats opened 6 years ago

systats commented 6 years ago

Hi Joshua: thanks for your great community effort!

The problem in my application is that if the number of words is decreased, the words does not disappear but overlay with the existing ones. This looks like:

screenshot 2018-04-18 21 20 43

A minimal example:

#devtools::install_github("jbkunst/d3wordcloud")
library(shiny)
library(d3wordcloud)
library(dplyr)

### demo data
df <- tibble(
  word = c("#btc", "#Bitcoin", "#BTC", "#Airdrop", 
    "#bitcoin", "#blockchain", "#cryptocurrency", "#eth", "#cr", 
    "#crypto", "#Cryptocurrency", "#dgb", "#digibyte", "#Digitize", 
    "#Eth", "#Ethereum", "#ico", "#ICO", "#LTC", "#usd"), 
  n = c(10L, 5L, 5L, 4L, 4L, 4L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L)
)

ui <- fluidPage(
   titlePanel("Beautiful Wordcloud with Bug"),
   sidebarLayout(
      sidebarPanel(
        sliderInput(inputId = "n_cloud", label = "", min = 5, max = 20, value = 10)
      ),
      mainPanel(
        d3wordcloud::d3wordcloudOutput("wordcloud")
      )
   )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

  toks <- reactive({
    toks <- df %>%
      dplyr::slice(1:as.numeric(input$n_cloud)) %>%
      dplyr::arrange(dplyr::desc(n))
  })

  output$wordcloud <- d3wordcloud::renderD3wordcloud({
    d3wordcloud(toks()$word, toks()$n, padding = 4, rotate.min = 0, rotate.max = 45, font = "Impact")
  })
}

shinyApp(ui = ui, server = server)

This bug reproduced on Mac, Windows and Shiny Server. Thanks for your effort! Best, Simon

jbkunst commented 6 years ago

Hi @systats !

Can you try without the the hashtag symbol?

jbkunst commented 6 years ago

Sorry, I will not run the reprex yet :P, I think is due the # symbol is reserved in the html world :sweat_smile:

systats commented 6 years ago
df <- tibble(
  word = c("#btc", "#Bitcoin", "#BTC", "#Airdrop", 
    "#bitcoin", "#blockchain", "#cryptocurrency", "#eth", "#cr", 
    "#crypto", "#Cryptocurrency", "#dgb", "#digibyte", "#Digitize", 
    "#Eth", "#Ethereum", "#ico", "#ICO", "#LTC", "#usd"), 
  n = c(10L, 5L, 5L, 4L, 4L, 4L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L)
) %>% mutate(word = stringr::str_replace(word, "#", ""))

Well, good idea, but it does change neither the overlapping nor persistence of words. Do you get the same output? Thanks for the quick response!

massimoaria commented 6 years ago

Hi, I have the same issue. When I change an input, the new word cloud overlap the previous one. So, after few changes, the plot became unreadable