# Update AppendTo when interacting with PopupMenu?

**URL:** <https://community.wolfram.com/t/update-appendto-when-interacting-with-popupmenu/13791>\
**Category:** Questions\
**Tags:** mathematica, interface-construction, ui-ux-and-ide\
**Created:** [March 15, 2019, 2:46pm UTC](https://community.wolfram.com/t/update-appendto-when-interacting-with-popupmenu/13791 "2019-03-15T14:46:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt2](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@matt2](https://community.wolfram.com/u/matt2)\
**Post date:** [March 15, 2019, 2:46pm UTC](https://community.wolfram.com/t/update-appendto-when-interacting-with-popupmenu/13791/1 "2019-03-15T14:46:49Z")

</div>

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]

```

[AppendTo doesn’t update when interacting with PopupMenu.nb](https://community.wolfram.com/uploads/short-url/q8zgqze4ScuDxd3lf2bOCH5oB2C.nb) (7.98 KB)

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [March 15, 2019, 3:47pm UTC](https://community.wolfram.com/t/update-appendto-when-interacting-with-popupmenu/13791/2 "2019-03-15T15:47:51Z")

</div>

The `UnitConvert` is only done at the beginning. It is not dynamic.

---

<div class="post-metadata">

**Author:** ![matt2](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@matt2](https://community.wolfram.com/u/matt2)\
**Post date:** [March 15, 2019, 4:10pm UTC](https://community.wolfram.com/t/update-appendto-when-interacting-with-popupmenu/13791/3 "2019-03-15T16:10:00Z")

</div>

I tried including expression with `UnitConvert` inside the Button but the output was exactly the same, `AppendTo` didn’t update when interacting with `PopupMenu`

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [March 15, 2019, 9:15pm UTC](https://community.wolfram.com/t/update-appendto-when-interacting-with-popupmenu/13791/4 "2019-03-15T21:15:13Z")

</div>

This one updates the degrees:

```
DynamicModule[{inputList, inputData = 0, plotData = {}, 
  dataSet3 = {0, 0, 0}, dataSet1, dataSet2, dataSet4},
 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 = Quantity[FoldList[10 + (#1 - 10)*#2 &,
         inputData, dataSet2], "DegreesCelsius"];
      dataSet4 = Transpose[{inputList[[All, 1]], dataSet3}];
      AppendTo[plotData, dataSet4]],
    Spacer[5],
    PopupMenu[
     Dynamic[popupSelection], {"DegreesCelsius" -> "C", 
      "DegreesFahrenheit" -> "F"}], 
    ListPlot[
     plotData /. dgs_Quantity :> UnitConvert[dgs, popupSelection], 
     Joined -> True, ImageSize -> {300}, Frame -> True]}],
 SynchronousInitialization -> False]

```

---

<div class="post-metadata">

**Author:** ![matt2](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@matt2](https://community.wolfram.com/u/matt2)\
**Post date:** [March 15, 2019, 10:10pm UTC](https://community.wolfram.com/t/update-appendto-when-interacting-with-popupmenu/13791/5 "2019-03-15T22:10:17Z")

</div>

Gianluca thank you so much!!!
