# Generating Manipulate variables from a list of rules

I have the following list of rules:

minru = {"ksp" -> 0.3393, "pl" -> 0.3675, "qtz" -> 0.1628,
"hb" -> 0.0714552, "bi" -> 0.0476368, "sph" -> 0.006268,
"zrc" -> 0.000672, "ilm" -> 0.000168, "ap" -> 0.000348,
"aln" -> 0.000812, "cal" -> 0.002, "fl" -> 0.003}


I want to use this to make a Manipulate-able list as output. I want to turn the keys (rhs) into a set of variables and use the values (lhs) to define the range and initial parameters for the variables. I'm hoping to get a list of adjustable, normalised values within a manipulate frame with a slider for each input variable.

Here is the kind of thing I'm trying to achieve (minus the programatic variable definition):

Manipulate[
Module[{sum, vars},
sum = x + y + z;
vars = {x/sum, y/sum, z/sum}],
{{x, 0.33}, 0.001, 0.5, Appearance -> "Open"},
{{y, 0.33}, 0.001, 0.5, Appearance -> "Open"},
{{z, 0.33}, 0.001, 0.5, Appearance -> "Open"}]


What I've tried to far:

mantest[propru_] :=
Manipulate[
Module[{manvars, tot},
manvars = ToExpression[propru[[All, 1]]];
tot = Total[manvars];
(#/tot) & /@ manvars
],
Evaluate[Sequence @@
ReplaceList[propru,
KeyValuePattern[{x_ -> y_}] :>
{{ToExpression[x], y}, y - 0.5 * y, y + 0.5 * y}]]
]
mantest[minru]


Alas, Mathematica says "no"...

This question got me some of the way but the variable parameters (from lhs) still aren't working....

Any suggestions on how to do this? Do need to use Hold somewhere?

• does this give what you need: mantest[propru_] :=DynamicModule[{manvars=Symbol/@Keys[propru], values=Values@propru },Manipulate[Evaluate@Normalize[manvars ,Total],Evaluate[Sequence@@({{##},(1-.5)#2,(1+.5)#2}&@@@Transpose[{manvars, values}])] ]]; mantest[minru]? 
– kglr
Nov 6, 2018 at 1:45
• Do you want to apply a function to all values like Normalize[vars, Totla] or do you want to be able to use them separately e.g. ksp + aln.
– Kuba
Nov 6, 2018 at 10:21
• @kglr yes, that works nicely! If you have time, perhaps you should make it into an answer and perhaps explain why this works where my approach failed. Many Thanks! Nov 6, 2018 at 21:57
• @Kuba I not quite sure I understand. I'm aiming to perform a simple normalisation of the form var_i / sum(var). Does this make sense? Nov 6, 2018 at 21:59

mantest[propru_] := DynamicModule[{manvars = Symbol /@ Keys[propru],
`