Lchiffon / wordcloud2

R interface to wordcloud for data visualization.
397 stars 113 forks source link

add click event to `wordcloud2Output()` shiny function #35

Closed AdamSpannbauer closed 6 years ago

AdamSpannbauer commented 6 years ago

Added getClickedWord() function and the resulting functionality to renderWordcloud2.R.

AdamSpannbauer commented 6 years ago

Here is a minimal app demoing the click event functionality.

devtools::install_github("AdamSpannbauer/wordcloud2")

library(shiny)
library(wordcloud2)
shinyApp(
  ui=shinyUI(fluidPage(
    #using default clicked word input id
    wordcloud2Output("my_wc"),
    #using custom clicked word input id
    wordcloud2Output("my_wc2", clickedWordInputId = "wc2_clicked_word"),

    verbatimTextOutput("print"),
    verbatimTextOutput("print2")
  )),
  server=shinyServer(function(input,output,session){
    output$my_wc  = renderWordcloud2(wordcloud2(demoFreq))
    output$my_wc2 = renderWordcloud2(wordcloud2(demoFreq))

    #using default clicked word input id
    output$print  = renderPrint(input$my_wc_clicked)
    #using custom clicked word input id
    output$print2 = renderPrint(input$wc2_clicked_word)
  })
)
zschuster commented 6 years ago

@Lchiffon I've implemented click events with the additions to the wordcloud2 package proposed by @AdamSpannbauer . It'd be great to have the PR approved.

tedhwang commented 6 years ago

Hey guys. I'm not sure if this is a right place to ask question but if so, would it be possible, under the current setting, to implement clicking a word which would open the new window at a designated link attached to the word? Basically I'd like it to be one click and go, not having to click separate hyperlink shown in Shiny again.

AdamSpannbauer commented 6 years ago

@tedhwang as you mentioned, this isn't really the right place to ask questions like this. Pull Request threads are intended to be focused discussions concerning the PR itself.

StackOverflow is more geared towards questions like this. This SO Q/A covers the topic you're asking about. This gist uses the same JS function to directly cover your wordcloud2 use case. In the future keep SO in mind for these types of questions (even though you did get an answer this time).

tedhwang commented 6 years ago

Thanks so much for the kind answer. I'm not used to the culture of Github yet, and I totally understand your advice. Will use SO next time. (If you want my post to be deleted, I'd be glad to help)

Best Regards,

Ted

On Wed, Jun 13, 2018 at 7:26 AM Adam Spannbauer notifications@github.com wrote:

@tedhwang https://github.com/tedhwang as you mentioned, this isn't really the right place to ask questions like this. Pull Request threads are intended to be focused discussions concerning the PR itself.

StackOverflow is more geared towards questions like this. This SO Q/A https://stackoverflow.com/questions/41426016/shiny-open-multiple-browser-tabs/50837163#50837163 covers the topic you're asking about. This gist https://gist.github.com/AdamSpannbauer/d93af343214c09c0ee7ce035dcdee5e1 uses the same JS function to directly cover your wordcloud2 use case. In the future keep SO in mind for these types of questions (even though you did get an answer this time).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Lchiffon/wordcloud2/pull/35#issuecomment-396919130, or mute the thread https://github.com/notifications/unsubscribe-auth/AiTQoedrXRujLzYBVppiu1fXZRnSseTpks5t8QTYgaJpZM4RjvYQ .

Lchiffon commented 6 years ago

merged, thanks @AdamSpannbauer