2
$\begingroup$

I have a problem with PopupMenu inside DynamicModule, its values don't update dynamically as they supposed to. The example below demonstrates the issue.

DynamicModule[{inputData = 0, dataSet1 = {0}, popupSelection, value1, value2 }, 
 Dynamic@Column[{
    InputField[Dynamic[inputData]], 
    Button["Plot", dataSet1 = Table[inputData + i^j, {i, 5}, {j, 2}]],
     Spacer[5],
    PopupMenu[Dynamic[popupSelection], {value1 -> "v1", value2 -> "v2"}],
    ListPlot[popupSelection, Joined -> True, ImageSize -> {300}, 
     Frame -> True]}],
 Initialization :> (
   value1 = dataSet1;
   value2 = dataSet1 + 1;
   ), 
 SynchronousInitialization -> False]

The PopupMenu is linked to ListPlot, for example: if value1 with label "v1" is selected from the list then ListPlot should print the evaluated value of value1 and the same goes for value2.

The problem I have is that value1 and value2 which correspond to popupSelection don't update dynamically when changing the input of InputField and pressing button "Plot". These values evaluate only once (upon DynamicModule evaluation) using initial values and they do not re-evaluate when required. I tried to wrap expressions of value1 and value2 with Dynamic but it conflicts with ListPlot giving me bunch of error messages.

I know i'm missing something here, I just can't figure out what it is. Please help!

cross-posted on Wolfram Community

Edit:

The question has been answered on Wolfram Community

$\endgroup$
  • $\begingroup$ Kamila, perhaps you could summarize the solution proposed by Wolfram Community in an answer of yours here, so the question will show up as answered for future users. Links may easily break in the future and the solution may be overlooked. $\endgroup$ – MarcoB Mar 13 at 17:57
  • 1
    $\begingroup$ You initialize value1 and value2 but you never update them in DynamicModule. You update dataSet1 but that is not linked to value1 and value2. You could get it mostly working by swaping Set for SetDelayed in the Initialization option. $\endgroup$ – Edmund Mar 13 at 22:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.