2
$\begingroup$

I'm wondering if it's possible to set actions to the words in a WordCloud. I'd like to press a word and have it printed. I noticed here that Button[] can be used like ToolTip[] so changed the example code

entities = EntityValue[CountryData[], {"Name", "Population"}];
WordCloud[{Tooltip[#[[1]], #[[2]]], #[[2]]} & /@ entities]

into this but didn't work 'cause strings were expected. Then I thought that maybe an hyperlink would work but this only works with URL, right?

WordCloud[{Button[#[[1]], Print[#[[1]]]]} & /@ entities]

Thank's for your help

$\endgroup$
  • 3
    $\begingroup$ try WordCloud[{Button[#[[1]], Print[#[[1]]]]} & /@ entities] or WordCloud[{Button[#[[1]], Print@ #], #[[2]]} & /@ entities] $\endgroup$ – kglr Sep 8 at 4:05
  • $\begingroup$ Thank's, the second option worked $\endgroup$ – Mara Luisa Amada Tercero Sep 8 at 14:55
5
$\begingroup$

The elements of the input list should be of the form {Button[$string_i$, $action_i$], $weight_i$} or,for unweighted data, just Button[$string_i$, $action_i$]. So

 WordCloud[{Button[#[[1]], Print@#], #[[2]]} & /@ entities]

works as expected:

enter image description here

You can remove the braces around Button[...] in your code to get an unweighted word cloud:

WordCloud[Button[#[[1]], Print@#] & /@ entities]

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.