Here is a bit of code:

funlist = {Plot,ListPlot};
Input[Panel[PopupMenu[Dynamic@whichfun, funlist], "blabla"],Dynamic@whichfun]

The idea here is to select what function you want to use (Plot or ListPlot in that case) and to give the expression you want to be evaluated by this function (for example x,{x,0,1} for Plot).

I have been struggling with this code for a few hours so if anyone has an idea.

I am aware that something like:

PopupMenu[Dynamic@whichfun, funlist]
InputField[Dynamic[expr], String, ContinuousAction -> True]
Dynamic@(whichfun @@ (ToExpression@expr))

with InputField fed by {x, {x, 0, 1}} would work.

  • $\begingroup$ Input is a must? $\endgroup$ – Kuba Oct 1 '13 at 15:58
  • $\begingroup$ Input is a wish*. If it's not possible then I'll give up. $\endgroup$ – Öskå Oct 1 '13 at 16:00
  • 1
    $\begingroup$ You could strip away the Dynamic stuff that gets in the way: Input[....]/. Dynamic[f_, ___] :> f $\endgroup$ – ssch Oct 1 '13 at 16:05
  • $\begingroup$ @ssch, it indeed works! Answer it? $\endgroup$ – Öskå Oct 1 '13 at 16:13

This feels like a bit of a hack but at least works. The output looks something like:

(* Dynamic[whichfun, ImageSizeCache -> {33., {0., 8.}}][x, {x, 0, 1}] *)

After stripping away that Dynamic it works as expected:

funlist = {Plot, ListPlot};
  Panel[PopupMenu[Dynamic@whichfun, funlist], "blabla"],
  Dynamic@whichfun] /. Dynamic[f_, ___] :> f
(* Gives a plot *)

Your Answer

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

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