Wordcloud2 - Click Event and Mouse pointer

322 views Asked by At

I recently asked a question, rather it is possible to change the mouse to a pointer, when it hovers over the words in a wordcloud in shinyapp. The answer worked successfully.

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

# Define the UI
ui <- bootstrapPage(
  tags$head(tags$style(HTML('.wcLabel {cursor: pointer; pointer-events: auto !important;}'))),
  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)

But now, input$Wordcloud_clicked_word won't react anymore.

(Edit: as HubertL correctly mentioned, using click event in the package of CRAN is not possible. However, installing the Version of GitHub makes it possible as noted here. So devtools::install_github("lchiffon/wordcloud2") is needed to make click events possible)

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

# Define the UI
ui <- bootstrapPage(
  tags$head(tags$style(HTML('.wcLabel {cursor: pointer; pointer-events: auto !important;}'))),
  numericInput('size', 'Size of wordcloud', n),
  wordcloud2Output('wordcloud2'),
  verbatimTextOutput("ClickedWord")
)

# Define the server code
server <- function(input, output) {
  
  output$wordcloud2 <- renderWordcloud2({
    # wordcloud2(demoFreqC, size=input$size)
    wordcloud2(demoFreq, size=input$size)
  })
  
  output$ClickedWord <- renderText(input$wordcloud2_clicked_word)
  
}

# Return a Shiny app object
shinyApp(ui = ui, server = server)

When I change .wcLabel, then the verbatimTextOutput won't react anymore on clicking on a word in the cloud.

Is it possible to have both, the mouse changing to pointer on hover and reacting to clicking on a word?

Thanks!

Frederik

0

There are 0 answers