微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Wordcloud2 - 单击事件和鼠标指针

如何解决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;}'))),verbatimtextoutput("ClickedWord")
)

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

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

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

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

谢谢!

弗雷德里克

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。