2

I want to work with lists within the CDF player. A very simple example, which works inside a notebook is

DynamicModule[{x = {1, 2, 7}}, 
 Panel[Column@{InputField[Dynamic@x, Expression], Dynamic@func@x}], 
 Initialization :> (func[x_] := 2*ToExpression[x])]

Exported as a stand alone CDF application this does not work. Changing input x results in nothing!

If x is a Number then it works also in the CDF player.

kglr
  • 394,356
  • 18
  • 477
  • 896
perlt
  • 21
  • 1
  • 4
    From http://www.wolfram.com/cdf/faq/details-for-mathematica-programmers.html : "Non-numeric input fields are not supported. Avoid InputField[x, String] and InputField[x, Boxes]. InputField[x, Expression] and InputField[x] are restricted to work only with numbers, and InputField[x, Number] works normally." – Szabolcs Jan 31 '13 at 14:37

1 Answers1

3

If you only need to input lists of numbers, you can use a single InputField to select the length and generate one InputField per entry:

DynamicModule[{a = {0, 0, 0, 0, 0}, m = 5},

{Row[{
  InputField[Dynamic[m], Expression, ImageSize -> 40],
   DynamicWrapper[
     Dynamic@Table[With[{i = i}, 
        InputField[Dynamic[a[[i]]], ImageSize -> 30]]
     , {i, 1, m}]
   , If[Length@a =!= Round@m, a = PadRight[a[[1 ;; Min[m, Length[a]]]], m]]]
 }], Dynamic[a]}
 ]

Now the user can change the length of the list, and the elements of it:

The resulting interactive list generator

jVincent
  • 14,766
  • 1
  • 42
  • 74
  • Thank you for your advice. But mostly I would need a list of tuples or so. E.g. {{a,b,2},{r,f,3},...} I think this would be rather difficult to realize?! – perlt Jan 31 '13 at 19:44
  • @perit Your example ("E.g.") contains nonnumeric expressions (a, b, r, f) which are not supported, no matter how one tries to program the ability to enter the components of lists. – Michael E2 Feb 01 '13 at 03:43