I've just started playing around with dynamic elements and I am confused over where exactly I should be placing Dynamic[] in an expression. My reading of the related help is it should be around the part which is changing. However I find inconsistent behaviour.
For example:
DynamicModule[{r = 1}, {Slider[Dynamic[r]], Graphics[Circle[{0, 0}, Dynamic[r]], Axes -> True, PlotRange -> {{-1, 1}, {-1, 1}}]}]
works while
DynamicModule[{x = 1}, {Slider[Dynamic[x]], Plot[Sin[10 y Dynamic[x]], {y, 0, 2 Pi}]}]
doesn't and dynamic must be placed further out like this
DynamicModule[{x = 1}, {Slider[Dynamic[x]], Dynamic[Plot[Sin[10 y x], {y, 0, 2 Pi}]]}]
to work properly.
So my question is how do I determine where to place the Dynamic part in my expression? My thinking was with less inside the expression then it is less computationally expensive. Or if it doesn't make any difference should I just do
DynamicModule[{initial stuff},Dynamic[{everything}]]
DynamicModule[{r = 1}, {Slider[Dynamic[r]], Dynamic@NumberForm[r, {3, 2}], Dynamic@Graphics[Circle[{0, 0}, r], Axes -> True, PlotRange -> {{-1, 1}, {-1, 1}}]}]– Syed Jun 21 '22 at 05:44