I am trying to generalize a Manipulate
construct into a DynamicModule
one to try and include smoother controls, but I seem to be running afoul of Dynamic
's compartmentalization of my intermediate variables inside what used to be a Module
.
More specifically, I used to have a construct of the form
Manipulate[
Module[{y},
y = f[x];
{x, g[y]}
]
, {x, 0, 1}]
including (a large number of) intermediate expressions like y=f[x]
, and which produced output like
I now want to move control of the variable x
into the Module
- essentially, into a LocatorPane
command - but I don't know what the correct translation of the code above should be. My naive attempt is to so something like
DynamicModule[{x, y},
y = f[x];
{Slider[Dynamic[x]], Dynamic[x], Dynamic[g[y]]}
]
and this produces no errors but the output inside g
fails to update:
What is the correct generalization of the Manipulate[Module[ ... ] ]
combination? I have tried inserting Dynamic
commands in all possible combinations but I cannot seem to get them right. I know the answer is probably fairly basic, but I'm also a bit lost in the maze of tutorials for these commands.
Obviously, simply doing {Slider[Dynamic[x]], Dynamic[x], Dynamic[f[g[y]]]}
is not an option in my case. The intermediate calculations f[x]
are quite a few and very verbose, and the 'displayable' function g[y]
is actually several rather long and slow plotting commands. I need to do the central bit of the computation only once, and I do not want to repeat myself in giving it to the plotting commands.
What am I missing here? It feels very basic but I can't seem to get it right.