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 Association
s, 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.