I want to control the variables (and other options) used in a plot through a number of popup menus. As the plot takes a little time to be drawn, I want to be able to make a selection on each of the popup menus before the plot is drawn.

As a bonus challenge, I'd like the user to be able to control when the plot is drawn by pressing a button - however, I want to deploy this using Mathematica Online and Button cannot be cloud deployed.

Below is a toy example of my code so far. I use dynamic to link the popup menus to the plot. The problem is that it is a little too dynamic. I have tried using hold and unevaluated, then releasing/evaluating with a button but I couldn't get it to work.

(* create an association of variable values (random numbers) and variable names, a to e *)
values = AssociationThread[CharacterRange["a", "e"],RandomReal[{0, 1}, {5, 10}]];

(* define variable names *)
vars = Keys@values;

DynamicModule[{xvalue, yvalue},{
(* x value popup menu *)
PopupMenu[Dynamic[xvalue], vars],
(* x value popup menu *)
PopupMenu[Dynamic[yvalue], vars],
(* the plot *)
Dynamic[ListPlot[Transpose[{values[xvalue], values[yvalue]}]]]}]

So my two questions are:

  1. How can I let the user control the evaluation of the plot such that they can choose all options from popup menus before evaluating the plot?
  2. Is there a cloud-deployable alternative to Button?

Any suggestions would be much appreciated!


1 Answer 1


You can use the second argument of Dynamic so that the plot changes only after the y popup menu is selected.

DynamicModule[{x0 = "a", xvalue = "a", y0 = "a", yvalue = "a"},
 {(* x value popup menu *)
  PopupMenu[Dynamic[x0], vars],
  (* y value popup menu *)
    (xvalue = x0; yvalue = y0 = #) &], vars],
  (* the plot *)
  Dynamic[ListPlot[Transpose[{values[xvalue], values[yvalue]}]]]}]
  • $\begingroup$ Thanks for the answer! $\endgroup$
    – pgrad
    Sep 30, 2015 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.