Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Click Event and Mouse pointer #74

Open
fomofahg opened this issue May 26, 2021 · 0 comments
Open

Click Event and Mouse pointer #74

fomofahg opened this issue May 26, 2021 · 0 comments

Comments

@fomofahg
Copy link

This is a copy of a questioned I asked over at stackoverflow.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant