0
$\begingroup$

I am trying to take a user's input, which will determine as list of results. I would like to show that list to the user, one result at a time. Something like the following (which is broken):

Panel[Column[{
   Row[{"How many squares? ", InputField[Dynamic[x], Number]}],
   (*m=1 so that no out of range error for x < m:*)
   Row[{ButtonBox["Squares!", Evaluator -> Automatic, 
       ButtonFunction -> (m = 1; (r = Map[#^2 &, Range[x]]) &), 
       Appearance -> "DialogBox"] // DisplayForm}],
   Row[{SetterBar[Dynamic[m], Dynamic[Length[r]]]}],
   Row[{r[[m]]}]
   }]]

It seems that the trouble I am running into is setter bar not taking a dynamic range. I also tried using previous and next buttons which would increment or decrement x modulo m, but Mod[m,x] wasn't happy with a dynamic argument either. Any help would be greatly appreciated.

$\endgroup$
1
  • 1
    $\begingroup$ First of all, Length[r] will be an integer which will not work as a second argument of a SetterBar. Moreover Dynamic head stays there so something like Dynamic @ Range @ Length @ r will not be recognized as a List correctly. You have to move that Dynamic outside the Setterbar. $\endgroup$
    – Kuba
    Commented May 2, 2016 at 7:27

1 Answer 1

1
$\begingroup$

You can try with Manipulate

Manipulate[Row[{SetterBar[Dynamic[y], Range[x]], Dynamic[y]}], 
 {{x, 1,"Squares"}, InputField[#, Number] &}]

enter image description here

$\endgroup$

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