I'm trying to ListPlot a list calculated by the Button called "Plot" with PopupMenu linked to ListPlot to control the temperature units of displayed data, for example: if "DegreesCelsius" -> "C" is selected from the list then ListPlot should show plotted curve in "DegreesCelsius" and the same goes for "DegreesFahrenheit". AppendTo is used here to ListPlot new list every time the input of InputField is changed and Button is pressed by appending it to the old one.
My Problem is that the temperature units of the plotted curves don't change when selecting different values from PopupMenu. AppendTo doesn't update accordingly. I can see that popupSelection variable changes when interacting with PopupMenu but plotData variable only changes when Button is pressed, using current PopupMenu selection.
If I remove AppendTo from Button and include dataSet4:=Transpose[...] instead, as well as keeping it in Initialization everything works as I wanted. I tried to make several changes by shifting things around but nothing helped.
Please Help!
The example below demonstrates the issue.
DynamicModule[{},
inputList = {{1, 5}, {2, 4}, {3, 8}};
Dynamic@Column[{
InputField[Dynamic[inputData]],
Dynamic@Button["Plot",
dataSet1 = Map[Norm, Differences[inputList]];
dataSet2 = Exp[-N[Pi]*0.345*5*dataSet1/(10*2000)];
dataSet3 = FoldList[10 + (#1 - 10)*#2 &, inputData, dataSet2];
AppendTo[plotData, dataSet4]], Spacer[5],
PopupMenu[Dynamic[popupSelection], {"DegreesCelsius" -> "C", "DegreesFahrenheit" -> "F"}],
ListPlot[plotData, Joined -> True, ImageSize -> {300}, Frame -> True]}],
Initialization :> (
popupSelection = "DegreesCelsius";
inputData = 0;
plotData = {};
dataSet3 = {0};
dataSet4 := Transpose[{inputList[[All, 1]], QuantityMagnitude@UnitConvert[QuantityArray[dataSet3, "DegreesCelsius"], popupSelection]}];),
SynchronousInitialization -> False]
Attachments: