Hello everyone! I’m rather new to Mathematica, and although I understand the basics regarding Module, Block, and DynamicModule, I have come across some unexpected behavior when I use Manipulate to change the graph to be plotted when inside a DynamicModule. Below is the code for when I wrap the Manipulate with DynamicModule:
The SetterBar behaves as expected when you click between the square function and the cubic function (with the square function selected above), but the SetterBar looks differently than the following code:
I understand that the variable names are different between the two examples because DynamicModule localizes the variables (by adding $$ and numbers after the variable name), but why did the highlighting functionality stop working? It is also a curious thing to note that replacing DynamicModule with either Block or Module will produce the expected behavior for the SetterBar.
One other thing I noticed - Why is the function not offset by 5 like expected?
I haven’t looked into this very closely, but I see the following option setting in the Manipulate`ManipulateBoxes subexpression in the cell expression of the output:
This seems to determine the control labels we see. If $$ is removed from both of the localized x and y symbols, the control labels appear “normally” when you revert the cell expression --- and everything seems to work fine still, with the added bonus that the buttons are highlighted when they are selected.
I think an interesting thing to note here is that fcn$$ “works” fine, i.e. it displays without $$ in the control label. Also, if you remove $$ from fcn$$, the control (understandably) no longer sets the localized fcn symbol.
Sorry I don’t have an answer for you, but this is interesting and I’d also like to know why it’s happening.
Martin, Thanks for the reply. That is a wonderful thing to point out, and I’m glad you did. You can use a rule in the Manipulate construct to override the default label. However, this does not address the problem I have, which can be summarized as such:
Why does the SetterBar highlighting behavior not work properly when I wrap the Manipulate with a DynamicModule? Some input would be much appreciated!
Thanks,
Tom
The behavior of the dynamic variables was answered.
Your other issue has to do with hown displays graphics by default. If you look carefully at the graph, the graph starts at y = 5. To make sure that the axes go through {0,0}, you have to use the option AxesOrigin.
George, thanks for the information about the plotting. Do you have any input regarding why the highlight behavior for the SetterBar does not work when the Manipulate is wrapped around with a DynamicModule? That is what I would really like to know, and I can’t seem to find the answer!
Thanks,
Tom