Wordcloud2 - change the cursor to pointer, when hover over words

400 views Asked by At

I want to make a Shiny App with a Wordcloud. But I'm having problems on changing the outcome, when the mouse hovers over the Words. What I want is, that the mouse of the user changes to a pointer, when it hovers over the words.

I tried to put it in some kind of css-class (without really knowing, what I have done), based on answers from here and here

#in the body ui
(tags$head(tags$style(HTML('div#wcLabel {cursor: pointer;}')))

but it didn't work.

Here is a reproducible example

library(shiny)
library(wordcloud2)
# Global variables can go here
n <- 1

# Define the UI
ui <- bootstrapPage(tags$head(
  tags$style(HTML('div#wcLabel {cursor: pointer;}'))
),
  numericInput('size', 'Size of wordcloud', n),
  wordcloud2Output('wordcloud2')
)


# Define the server code
server <- function(input, output) {
  output$wordcloud2 <- renderWordcloud2({
    # wordcloud2(demoFreqC, size=input$size)
    wordcloud2(demoFreq, size=input$size)
  })
}
# Return a Shiny app object
shinyApp(ui = ui, server = server)

I know that there is a call hoverFunction = in the wordcloud2() function, and I guess, I would have to put something in there, to achieve my goal, but I don't know what.

Any help would be really appreciated. Many Thanks!

Frederik

1

There are 1 answers

1
MattW On BEST ANSWER

#wcLabel has pointer-events: none; set by default. You can override that by using the !important rule.

div#wcLabel {cursor: pointer; pointer-events: auto !important;}