In short: Wrap Dynamic around the "construction" of the Association:
DynamicModule[
{g = 0.05},
{
Manipulator[Dynamic[g], ContinuousAction -> False],
Append[List[], Dynamic[g]],
Dynamic@Append[Association[], "test" -> Dynamic[g]]
}
]
Manipulate effectively does something along these lines (in fact it wraps Dynamic around everything), which is why it works while your DynamicModule doesn't.
The reason it fails without the Dynamic is a bit involved, but essentially it boils down to the fact that Associations, once constructed, keep their contents unevaluated/protected in some sense (see e.g. this question & related). This means that e.g. Module localization doesn't work within constructed associations (something similar to the following is happening inside DynamicModule):
<|a -> b|> /. x_ :> Module @@ Hold[{b = 2}, x]
(* <|a -> b|> *)
{a -> b} /. x_ :> Module @@ Hold[{b = 2}, x]
(* {a -> 2} *)
Note how the b in the first example has not been replaced by 2 like one might expect. Wrapping Dynamic around the association constructions delays said construction until after DynamicModule has done its job and has localized all the variables.
DynamicModule[{g = 0.05}, {Append[Association[], "test" -> Dynamic[g]], Manipulator[Dynamic[g], ContinuousAction -> False]}]and alsoDynamicModule[{g = 0.05}, {Append[Association[], "test" -> Dynamic[g]] Manipulator[ Dynamic[g], ContinuousAction -> False]}](note the missing comma), moving the latter slider affects the fomer!? – Alan Jul 14 '23 at 20:47Dynamic[g], as well as theDynamic[g]occurrences of the associations of bothDynamicModuleexpressions are inside an association (after the expressions have been evaluated at least): As a result, the localization fails as outlined above, and thegthat is being manipulated/displayed is not the one from aDynamicModule, but rather the global variableg(you can check this by evaluatinggin a separate cell) – Lukas Lang Jul 14 '23 at 21:06