2

In this question Manipulate with a variable number of sliders one of the answer is

DynamicModule[{n = 5, data = Table[RandomReal[], {20}]}, 
 Column[{Slider[Dynamic[n], {1, 20, 1}], 
   Dynamic[Grid[
     Table[With[{i = i}, {Slider[Dynamic[data[[i]]]], 
        Dynamic[data[[i]]]}], {i, n}]]]}]]

Unfortunately the sliders are developped up to down and I wonder if there is a way to develop them side by side or positionned in a matrix.

Here is the normal behavior

---s---

---s1---

---s2---

---s3---

which after expansion will give

---s---
---s1---

---s2---

---s3---

---s4---

---s5---
. . .

I want --- because it takes less space

---s---
---s1--- ---s3---

---s2--- ---s4---

---s5--- .

   .            .    

   .            . 

   .            .

and why not with 3 or more columns

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
cyrille.piatecki
  • 4,582
  • 13
  • 26

1 Answers1

4

Answer to the question after editing

You can use Multicolumn to automatically format elements of a list arranged in a grid of many columns.

DynamicModule[
 {
  n = 5,
  data = Table[RandomReal[], {20}]
  },
 Column[
  {
   Slider[Dynamic[n], {1, 20, 1}],
   Dynamic[
    Multicolumn[
     Table[
      With[{i = i}, 
       Column[{Slider[Dynamic[data[[i]]]], Dynamic[data[[i]]]}]], {i, 
       n}]
     , 3]
    ]
   }
  ]
 ]

Mathematica graphics

Answer to the question before editing

Change Column for Row. Transpose the table.

DynamicModule[
 {
  n = 5
  , data = Table[RandomReal[], {20}]
  },
 Row[
  {
   Slider[Dynamic[n], {1, 20, 1}],
   Dynamic[
    Grid[Transpose@Table[
       With[{i = i}, {Slider[Dynamic[data[[i]]]], Dynamic[data[[i]]]}]
       , {i, n}]
     ]
    ]
   }
  ]
 ]
rhermans
  • 36,518
  • 4
  • 57
  • 149
  • I have edited the question. Hope to have been clearer – cyrille.piatecki Aug 24 '17 at 08:55
  • 3
    @cyrille.piatecki, doe this answer the new question? In the future, please explain what you need in the question in detail from the beginning. If you then realize you need something different, ask another question. Read here. Now, let's do a clean up of the obsolete comments. – rhermans Aug 24 '17 at 09:05