Wordcloud2 - 单击事件和鼠标指针

时间:2021-05-04 18:07:27

标签: r shiny hover click wordcloud2

我最近 asked a question,而是可以将鼠标更改为指针,当鼠标悬停在 Shinyapp 中 wordcloud 中的单词上时。答案成功。

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)

但现在,input$Wordcloud_clicked_word 不会再有反应了。

(编辑:正如 HubertL 正确提到的,在 CRAN 包中使用 click 事件是不可能的。但是,安装 GitHub 版本使其成为可能as noted here。 所以需要 devtools::install_github("lchiffon/wordcloud2") 才能使点击事件成为可能)

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)

当我更改 .wcLabel 时,verbatimTextOutput 将不再在点击云中的单词时做出反应。

是否可以同时拥有,鼠标在悬停时变为指针并在点击单词时做出反应?

谢谢!

弗雷德里克

0 个答案:

没有答案