After running below code

     data = Range[10];
     temp = {};
       Button["reset", temp = {}],
       TogglerBar[Dynamic[temp], data, Appearance -> "Horizontal" -> {Automatic, 5}],

I got

enter image description here

Now I want to copy the dynamically generated list and paste it elsewhere. But I found sometimes it works, sometimes it is not. You can see below gif

enter image description here

What is wrong with my code? Why sometimes it gives temp$$, sometimes not? How to make dynamic results easy to copy?


With Kuba's method to view "SelectionData", it is clear what is going on, see below gif. So proper selection will give expected result instead of temp$$

enter image description here

  • 1
    $\begingroup$ It is probably a subtle problem with what you really select, if whole DynamicBox or not. To achieve a stable behavior you can use InputField@Dynamic[temp] for example. $\endgroup$ – Kuba Sep 14 '16 at 11:34
  • 1
    $\begingroup$ Yes, I think, @Kuba is right about whether you select the whole DynamicBox or its contents. -- The menu command Cell > Show Expression will reveal what you actually pasted. $\endgroup$ – Michael E2 Sep 14 '16 at 11:36
  • $\begingroup$ Hi, @MichaelE2. But I can not see any difference between two cases by looking at " Show Expression". where is the difference? $\endgroup$ – matheorem Sep 14 '16 at 11:54
  • $\begingroup$ @matheorem with ShowExpression you only see what is written in a notebook file. There is another layer, on that FE really displays, so DynamicBox is there but FE keeps track what it really represents. In this case a box representation of temp. More or less ;) $\endgroup$ – Kuba Sep 14 '16 at 13:29
  • 1
    $\begingroup$ Syntax highlighting can assist your selection process. If the cursor is placed directly after the }, then { } will be highlighted and you'll be selecting the right thing. If the cursor is placed too far after }, then there is no syntax highlighting and you'll be selecting the DynamicBox. One can use the arrow key to move to the correct position. Double-clicking on { or } also results in a correct selection. $\endgroup$ – Karsten 7. Sep 15 '16 at 7:59

Quick fix:

To achieve a stable behavior you can use e.g. InputField @ Dynamic[temp].

More about the issue:

It is probably a subtle problem with what you really select, if whole DynamicBox or not.

To see what is going on you can use

Dynamic @ InputForm @ CurrentValue @ "SelectionData"

and check what is selected in certain steps, sometimes it is

DynamicBox[ToBoxes[temp$$, StandardForm], ....] (*displayed as `temp$$`*)

and sometimes a RowBox with numbers. In the latter case you got what you were expecting.

  • $\begingroup$ InputField is great! upvoted! Thank you so much! I need more time to understand the remaining part : ) $\endgroup$ – matheorem Sep 14 '16 at 11:50
  • $\begingroup$ "SelectionData" works like magic, very interesting : ) $\endgroup$ – matheorem Sep 15 '16 at 7:38
  • $\begingroup$ @matheorem I'm glad it fits yor needs :) Thanks for the accept. $\endgroup$ – Kuba Sep 15 '16 at 7:38

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.