jbkunst / d3wordcloud Goto Github PK
View Code? Open in Web Editor NEW:cloud: htmlwidgets for D3js Word Cloud Layout
Home Page: http://rpubs.com/jbkunst/133106
:cloud: htmlwidgets for D3js Word Cloud Layout
Home Page: http://rpubs.com/jbkunst/133106
Current behaviour: when the browser window is resized, the wordcloud remains static. This is desirable in some cases, and not in others. I won't provide my own example, since your own demo app shows the current behaviour :)
https://jbkunst.shinyapps.io/d3wordcloud/
Enhancement: It would be really neat if there could be an option for the wordcloud to be redrawn when the browser window is resized. This would be especially useful when using the wordcloud within a shiny::column()
div, whose width will change with the browser window.
Suggestion: This might be achievable without changing the parameters of the functions. If the width is a percentage, it could resize by default. If it's a number of pixels, it would not. I don't know whether there are any unwanted side effects from that, so it might yet be a terrible way of doing it.
Obligatory yet sincere praise: I really like this package! Great work.
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
Thank you for this package; it is great. Unfortunately, I've found that one of the scripts conflicts with custom styles elsewhere in a document. Specifically, this line from an Rmarkdown document that uses d3wordcloud, rendered as HTML:
<script src="site_libs/d3wordcloud-1/d3.layout.cloud.js"></script>
clobbers font weights that are otherwise set in custom css. Oddly--to me, and probably stemming from my weak javascript knowledge--I can't override the effects of that script in Chrome developer tools or with !important
.
Any thoughts on a solution? I prefer this package over the static wordcloud
package.
Hi,
Thank you so much for working on this great package! It is very helpful to visualize the result on shiny. I was using simpleNetwork under the networkD3 packages (https://christophergandrud.github.io/networkD3/) along with your d3wordcloud packages.
Somehow, it render perfectly fine under local for both d3wordcloud and simplenetwork. It works also fine if i render on shiny for simpleNetwork or d3wordcloud by itself. But it doesnt show both together and doesnt give me any error message. Could you please help me with this?
Thanks,
Sherry
In this simple example only 1 of the 3 'words' is plotted.
words <-
structure(c(223L, 193L, 146L), .Dim = 3L, .Dimnames = structure(list(
c(
"CERTIFIED SERVICE MANAGER (CSM)", "CISCO CERTIFIED NETWORK ASSOCIATE",
"CISCO CERTIFIED NETWORK PROFESSIONAL (CCNP)"
)
), .Names = ""))
library("d3wordcloud")
set.seed(8297)
d3wordcloud(words= names(words), freqs = as.numeric(words), font = 'impact')
wordcloud
plots the 3:
library(wordcloud)
wordcloud(names(words),as.numeric(words), scale = c(1.5, 0.25))
Thanks!
Is it possible to add a tool-tip that shows, for example, the frequency of the word?
Thanks for the great package!
I have a wordcloud in Shiny and the tooltips are always way below the cursor. It seems like it is a standard gap too.
I edited d3wordcloud.js to change the "top" setting in function mousemove, but that did not work.
function mousemove(d){
tooltip
.style("left", (d3.event.pageX + 0 ) + "px")
.style("top", (d3.event.pageY + **0**) + "px");
}
How can I have the tooltip hover properly like found here: http://rstudio-pubs-static.s3.amazonaws.com/133106_df80b0877cfe45f2b8f06c03c60ffcab.html#tooltips
Is there a different location where I can change the top setting?
Excuse me, I want to render a word cloud in HTML, how to use the package?
Unable to run the d3word cloud from the github install
> library("d3wordcloud")
> words <- c("I", "love", "this", "package", "but", "I", "don't", "like", "use", "wordclouds!", "voila")
> freqs <- rev(seq(length(words))) + 10
>
> d3wordcloud(words, freqs)
Error in data.frame(text = as.character(words), freq = as.numeric(freqs), :
arguments imply differing number of rows: 11, 0
I'd like to use some other color palette in the wordcloud, is it possible?
Hi- First, thanks for a great widget. This is very helpful.
I've built a shiny app that interacts between visNetwork and d3wordcloud. I select a node (which is a topic, e.g. LDA) which will then populate the d3wordcloud.
The problem: after the first interaction, the wordcloud will not remove words that have not been used as a top word for new clicked nodes (topics).
The issue is because I do not use all words but only a subset -- the reason I need to limit is larger models when there's potentially 10,000+ words, I only want to plot the top 100 words.
Here's a simplified example, using a pre-created network and word-topic matrix consisting of 10 words and 6 topics (hence 10x6 matrix).
library(shiny); library(d3wordcloud); library(visNetwork)
# 6 topics
nodes <- data.frame(id = c(1,2,3,4,5,6))
edges <- data.frame(from = c(1,1,3,4,2,3), to = c(2,5,4,1,6,2))
# 10 words by 6 topics
probterms <- data.frame(x1 = c(0.05,0.1,0.2,0.2,0.20,0.05,0.05,0.05,0.05,0.05),
x2 = c(0.05,0.1,0.05,0.05,0.15,0.10,0.15,0.05,0.05,0.25),
x3 = c(0.1,0.15,0.05,0.05,0.05,0.05,0.15,0.10,0.25,0.05),
x4 = c(0.05,0.1,0.2,0.2,0.2,0.05,0.05,0.05,0.05,0.05),
x5 = c(0.05,0.2,0.05,0.2,0.15,0.05,0.05,0.15,0.05,0.05),
x6 = c(0.05,0.1,0.05,0.2,0.05,0.15,0.05,0.05,0.10,0.2))
rownames(probterms) <- c("ladder","hat","man","great","happy","dog","child","boy","hippo","football")
visNetwork(nodes, edges)
ui <- fluidPage(
fluidRow(
box(title = "Topic Network",
visNetworkOutput("topic.network", height = "400px"), width = 12)
),
fluidRow(
box(d3wordcloudOutput("topic.wordcloud", height = "200px"), width = 12
)
))
server <- function(input, output) {
output$topic.network <- renderVisNetwork({
visNetwork(nodes, edges) %>%
visOptions(nodesIdSelection = T) # must allow ID selection
})
terms <- reactive({
# selected topic
select <- as.integer(input$topic.network_selected)
# create data frame for selected topic probabilities
data.frame(word = rownames(probterms), prob = probterms[,select])
})
output$topic.wordcloud <- renderD3wordcloud({
w <- terms()
# sort word list by topic probability of selected topic (node)
w <- w[order(desc(w$prob)),]
# take only top 5 words -- if comment out, this is not a problem
w <- w[1:5,]
x <- d3wordcloud(w$word,
w$prob,
size.scale = "linear",
color.scale = "linear",
rotate.max = 0,
rotate.min = 0
)
})
}
shinyApp(ui = ui, server = server)
Notice that there is not a problem if you comment out line w <- w[1:5,]
, as when you update all words it words.
However, as I mentioned, I will need to use a subset of inputs as there are usually too many words and I'll need to reduce to (say) top 100.
I spoke with a colleague who is more familiar with D3 and javascript and he recommended that this problem could be solved by adding the line
d3.select(e1).html = "";
to line 231 to "/inst/htmlwidgets/d3wordcloud.js" to reset the word cloud to blank before rerunning the word cloud each time.
Essentially, I do not think this would effect anyone else as this just clears the cloud before running each time.
Would it be possible to make this change? If not, do you have any suggestions?
Worst case, I can create my own fork but for my app I need users to have access to this library, and therefore they would pull from my fork.
Hi,
I'm trying to put the clouds in a RMD and export to html with knitr in Rstudio, but my file came in blank and freezes Rstudio.
What options I need to use in the chunks? I need to do something special?
I tried results = "asis"
, but without success.
My reproducible example:
---
title: "test"
output:
html_document:
theme: flatly
highlight: tango
self_contained: FALSE
---
``{r source}
require(magrittr)
require(dygraphs)
ptcolsumm <- c("Usuários", "Sessões", "Pageview Único", "Pageviews", "Tempo Médio", "Rejeição", "Taxa de Rejeição", "Taxa de Saída", "não sei", "ACENTUAÇÃO", "Teste")
organic <- data.frame(organic = as.numeric(c(186,640,278,11,267,117,41,17,38)))
organic <- as.ts(organic)
# Facebook impressions by type
teste <- dygraph(organic) %>%
dySeries("organic", label = "Orgânico") %>%
dyLegend(width = 400, show = "always") %>%
dyOptions(fillGraph = TRUE, fillAlpha = 0.2, drawGrid = FALSE, drawPoints = TRUE, pointSize = 2)
``
<style> /* CSS style to solve the problem with the sparkline tooltip */
.jqstooltip {
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
}
</style>
## Quarterly Results {.tabset}
### By Region
``{r3}
teste
``
### BLOH BLOH 3
```{r wordcloudteste, results = "asis"}
require(d3wordcloud)
words <- c("I", "love", "this", "package", "but", "I", "don't", "like", "use", "wordclouds")
freqs <- sample(seq(length(words)))
d3wordcloud(words, freqs)
Thanks!
Very nice work! I assume this is not intentional:
df1 <- data.frame(word = LETTERS[1:10], freq = 1:10, stringsAsFactors = FALSE)
d3wordcloud(df1$word, df1$freq) # This works
df2 <- data.frame(a = LETTERS[1:10], b = 1:10, stringsAsFactors = FALSE)
d3wordcloud(df1$a, df1$b) # This does not work
Hi Joshua,
Thank you for your great package! I want to add the a wordcloud to a website. Since there is no connection with shiny I was wondering if it is possible to add a filter or some kind of control to the plot that enables the user to switch between different clouds based on different datasets or paramaters.
Is it easy to add a feature like that?
Kind regards,
Jelle
It seems, you haven't committed in a while. Is it possible to commit package for latest version of R. I tried with lower version of R 3.4.1 didnt worked out.
Thanks for this great package!
Is there a way to save/export the wordcloud as a png file? I would like to add this functionality to my wordcloud shiny app.
The word cloud is really awesome with manny cool features. In the word cloud created by JJason Davies. click funcitonality was there, but in this wrapper the click functionality is replaced by tooltip. Is it possible to have the on click functionlaity for each word in this word cloud as well?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.