How do I make a Module return values upon a button press?

I have put together a function of the form:

InteractiveInitialGuess[parametersymbols_, initialParamGuesses_] :=
Module[{plot, workingparams = Symbol["working" <> ToString[#]] & /@
parametersymbols, returnvals},
plot = NicePlot[xptData, integratedfn[xptData\[Transpose][[1]],
initialParamGuesses]];
Panel[Row[{Column[Join[parameterSelector @@@ ({workingparams,
initialParamGuesses,paramLabels}\[Transpose]),
{Button["Recalculate", plot = NicePlot[xptData,
integratedfn[xptData\[Transpose][[1]],
workingparams]]],
Button["Done", SelectionMove[EvaluationCell[],
All, Cell];
Paste[plot];
returnvals = workingparams;
Clear["working*"];
Return[returnvals]]}]],
Dynamic[plot]}]]]


The basic idea is that I have a set of parameters that I want to set (using dynamic modules defined by parameterSelector). I click a button to recalculate a graph (defined by the function NicePlot--the calculation is a numerical integration of coupled differential equations, and as such, they take too long to update on-the-fly, hence the button-to-recalculate approach). And when I am done, I want to replace the dynamic interface with the final plot and return the selected values. I seem to have all of that working except for the returning of the values. Any advice would be appreciated!

Implementation example:

I recognize that I have not provided fully-functional code. If that's really necessary for this question, I am happy to provide it, but it seems like a straightforward enough question that such code may not be necessary.

(Side note: It does appear that there is a calculation error in the model, because the strange hump around 1 ms shouldn't be there, but the question I am asking here should be independent of that issue.)

• What do you mean "return a value"? This Dynamic is occuring in the FE. If you want a value returned from a function like this you'll want to use DialogInput or such. May 10 '19 at 1:45
• While context matters it helps to have a simple example to show the problem and the description of what exactly is the desired behavior.
– Kuba
May 10 '19 at 9:21
• The basic idea is that I want to settle on some initial parameter values interactively through this panel, but when I have made the determination, I want the interactivity to be overwritten (to remove the overhead on the kernel—which I already accomplished using Paste), but also do a standard function return. So if I enter results=InteractiveInitialGuess[params,initGuesses], when Done is clicked, a list of the decided-upon parameter values will be assigned to the variable “result.” May 10 '19 at 16:52
• Hmmm. I suppose I could add another input field allowing the user to enter a symbol name for the results to be assigned to. Then upon a button-press, the results are assigned to that symbol. May 10 '19 at 17:01
• And that works for me. It doesn't address the original question, but I like this solution even better. May 10 '19 at 17:34

I added this in between my other two buttons:

Row[{Button["Assign values to:",
ToExpression[resultsLabel, StandardForm,
Function[name, name = workingparams, HoldFirst]]],
InputField[resultsLabel, String]}]


This is an even better solution, because it allows me to save different parameter selections to more than one symbol without having to start over each time.

• I appreciate your enthusiasm and I recognize that your problems are real and applicable to wider audience but without a simple example that anyone can run and the answer which addresses such example the topic is useful only for you. Please take a look at: what-do-we-mean-by-a-self-contained-minimal-working-example
– Kuba
May 11 '19 at 7:18
• Thank you for the criticism. I understand the utility of a self-contained minimal working example; when I was trying to construct one, I was having a very hard time making one that didn't remove some of the levels of complexity that might figure in to developing an answer to the question (e.g., I didn't know if the various levels of Dynamics were relevant or not). I will in the future try harder, however. Again, thank you for the constructive criticism. May 11 '19 at 18:41