d3wordcloud
d3wordcloud copied to clipboard
Unexpected Behavior (overlap and not disappear)
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:
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
Hi @systats !
Can you try without the the hashtag symbol?
Sorry, I will not run the reprex yet :P, I think is due the # symbol is reserved in the html world :sweat_smile:
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!
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