# \[?\] List layout using Grid?

**URL:** <https://community.wolfram.com/t/list-layout-using-grid/10921>\
**Category:** Questions\
**Created:** [July 11, 2017, 3:04am UTC](https://community.wolfram.com/t/list-layout-using-grid/10921 "2017-07-11T03:04:35Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![jorgeman49](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@jorgeman49](https://community.wolfram.com/u/jorgeman49)\
**Post date:** [July 11, 2017, 3:04am UTC](https://community.wolfram.com/t/list-layout-using-grid/10921/1 "2017-07-11T03:04:35Z")

</div>

Hello friends, I am new using Wolfram language and I have a problem.  
The issue is:

- I create two lists

- m & n are obtained by sliders and ct by means of a radio button

The pc and qc lists seem to be calculated correctly but when I use them in a Grid:

```
Grid [{pc, qc}, Frame -> All]

```

Does not seem to recognize them properly.  
The output is:

```
Grid [{{8, -2,5,4}, {- 3,7,1,4,5-1}}, Frame-> All]

```

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [July 11, 2017, 11:28am UTC](https://community.wolfram.com/t/list-layout-using-grid/10921/2 "2017-07-11T11:28:19Z")

</div>

I would move the definitions `pc=` and `qc=` inside `Dynamic`, so that the `Dynamic` wrapper does not interfere with `Grid`:

```
Slider[Dynamic[m], {1, 10, 1}]
Slider[Dynamic[n], {1, 10, 1}]
RadioButtonBar[Dynamic[ct], 10^-Range[10]]
Dynamic[pc = Rationalize[RandomReal[{-10, 10}, n + 1], ct*0.1]]
Dynamic[qc = Rationalize[RandomReal[{-10, 10}, m + 1], ct*0.1]]
Dynamic[Grid[{pc, qc}, Frame -> All]]

```

---

<div class="post-metadata">

**Author:** ![lvveen](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/lvveen/32/4003_2.png) [@lvveen](https://community.wolfram.com/u/lvveen)\
**Post date:** [July 11, 2017, 12:39pm UTC](https://community.wolfram.com/t/list-layout-using-grid/10921/3 "2017-07-11T12:39:42Z")

</div>

Grid[{Sequence @@ pc, Sequence @@ qc}, Frame → All]

---

<div class="post-metadata">

**Author:** ![jorgeman49](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@jorgeman49](https://community.wolfram.com/u/jorgeman49)\
**Post date:** [July 12, 2017, 1:16am UTC](https://community.wolfram.com/t/list-layout-using-grid/10921/4 "2017-07-12T01:16:51Z")

</div>

I move pc and qc into Dynamic, as you advise, it works well.  
But there is another related problem, I will try to explain with the code:

```
DynamicModule[{pc, n = 3, qc, m = 3, g, ct = 5},
 Column[{
   Row[{
     Column[{
       Slider[Dynamic[n], {1, 8, 1}, Appearance -> "Labeled"],
       Slider[Dynamic[m], {1, 8, 1}, Appearance -> "Labeled"]
       }],
     RadioButtonBar[
      Dynamic[ct], {5 -> Z], 
       1 -> Q]}]}
    ],
   Dynamic[
    pc = Function[g, Rationalize[g, ct*0.1]] /@ 
      RandomReal[{-10, 10}, n + 1]],
   Dynamic[
    qc = Function[g, Rationalize[g, ct*0.1]] /@ 
      RandomReal[{-10, 10}, m + 1]],
   Dynamic[Grid[{pc, qc}, Frame -> All]]
   }
  ]
 ]

```

If I run the above code, I get:

 ![Captura.JPG](https://global.discourse-cdn.com/wolfram/original/3X/f/e/fe7a5e1550516f0eaecd27496facd09352614b73.jpeg)

As expected, but I want to show, as a final result, only the grid.  
To hide the lists pc and qc I replace commas by semicolons where pc and qc are defined:

```
Dynamic[pc = 
  Function[g, Rationalize[g, ct*0.1]] /@ RandomReal[{-10, 10}, n + 1]];
Dynamic[qc = 
  Function[g, Rationalize[g, ct*0.1]] /@ RandomReal[{-10, 10}, m + 1]];
Dynamic[Grid[{pc, qc}, Frame -> All]]

```

But now the result is:

![3273Captura.JPG](https://global.discourse-cdn.com/wolfram/original/2X/3/33de780bc6519567eca9eee7e8532b67bf87c98d.jpeg)

I have previously programmed with functional languages like Haskell but this one has me confused.

Your help is and will be appreciated.

---

<div class="post-metadata">

**Author:** ![jorgeman49](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@jorgeman49](https://community.wolfram.com/u/jorgeman49)\
**Post date:** [July 12, 2017, 1:36am UTC](https://community.wolfram.com/t/list-layout-using-grid/10921/5 "2017-07-12T01:36:00Z")

</div>

Hello I Van, I did what you advised me with a small change:

```
DynamicModule[{pc, n = 3, qc, m = 3, g, ct = 5},
 Column[{
   Row[{
     Column[{
       Slider[Dynamic[n], {1, 8, 1}, Appearance -> "Labeled"],
       Slider[Dynamic[m], {1, 8, 1}, Appearance -> "Labeled"]
       }],
     RadioButtonBar[
      Dynamic[ct], {5 -> \[DoubleStruckCapitalZ], 
       1 -> \[DoubleStruckCapitalQ]}]}
    ],
   pc = Dynamic[
     Function[g, Rationalize[g, ct*0.1]] /@ 
      RandomReal[{-10, 10}, n + 1]],
   qc = Dynamic[
     Function[g, Rationalize[g, ct*0.1]] /@ 
      RandomReal[{-10, 10}, m + 1]],
   Dynamic[Grid[{Sequence @@ pc, Sequence @@ qc}, Frame -> All]]
   }
  ]
 ]

```

As you noticed, I wrapped the Grid inside a Dynamic. However I still have a problem, the partial results and the final result do not match:

 ![1064Captura.JPG](https://global.discourse-cdn.com/wolfram/original/3X/d/8/d810ca2de3d4d791150afe0d7e0e2b620893d16d.jpeg)

I guess it’s due to the call to RandomReal. But I do not know how to make them match, any use of pc or qc will invoke RandomReal again. I appreciate your help

---

<div class="post-metadata">

**Author:** ![lvveen](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/lvveen/32/4003_2.png) [@lvveen](https://community.wolfram.com/u/lvveen)\
**Post date:** [July 12, 2017, 6:04pm UTC](https://community.wolfram.com/t/list-layout-using-grid/10921/6 "2017-07-12T18:04:28Z")

</div>

Hi Jorge,  
I don’t understand exactly what you need. Your module will evaluate indeed different numbers after you change the values of m or n. If you want these values to remain the same I suggest you generate random numbers first ( a list of 9 numbers ) and then select these numbers with Part with the n and m.  
Or is this not what you mean because then you only select from a list. Could you show me what you expect when selecting m and n back and forth?

```
DynamicModule[{pc, n = 3, qc, m = 3, g, ct = 5, 
  rnd = RandomReal[{-10, 10}, 10]}, 
 Column[{Row[{Column[{Slider[Dynamic[n], {1, 8, 1}, 
        Appearance -> "Labeled"], 
       Slider[Dynamic[m], {1, 8, 1}, Appearance -> "Labeled"]}], 
     RadioButtonBar[
      Dynamic[ct], {5 -> \[DoubleStruckCapitalZ], 
       1 -> \[DoubleStruckCapitalQ]}]}], 
   pc = Dynamic[
     Function[g, Rationalize[g, ct*0.1]] /@ rnd[[;; n + 1]]], 
   qc = Dynamic[
     Function[g, Rationalize[g, ct*0.1]] /@ rnd[[;; m + 1]]], 
   Dynamic[Grid[{Sequence @@ pc, Sequence @@ qc}, Frame -> All]]}]]

```

---

<div class="post-metadata">

**Author:** ![jorgeman49](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@jorgeman49](https://community.wolfram.com/u/jorgeman49)\
**Post date:** [July 12, 2017, 7:18pm UTC](https://community.wolfram.com/t/list-layout-using-grid/10921/7 "2017-07-12T19:18:36Z")

</div>

Hello I van,

I want to generate two queues (qc and pc) of random numbers. Each queue should be generated “just in time” when the user manipulates the corresponding slider.

The queues will be used in a simulation system and the grid is a simplification of the actual output. It is important that the simulation be carried out with the same random numbers shown in the Grid.

Generating a larger list and taking n or m numbers at the time should work but: how long should it be initially? When should it regenerate? and so.

I hope I have explained clearly, thank you for your suggestions and contributions.

---

<div class="post-metadata">

**Author:** ![lvveen](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/lvveen/32/4003_2.png) [@lvveen](https://community.wolfram.com/u/lvveen)\
**Post date:** [July 12, 2017, 8:26pm UTC](https://community.wolfram.com/t/list-layout-using-grid/10921/8 "2017-07-12T20:26:00Z")

</div>

Hi Jorge, I think you should then use the suggestion from Jorge Manrique .  
This is what you want. The Set (=) is used inside Dynamic and is the regular way to do it.

```
DynamicModule[{pc, n = 3, qc, m = 3, g, ct = 5}, 
 Column[{Row[{Column[{Slider[Dynamic[n], {1, 8, 1}, 
        Appearance -> "Labeled"], 
       Slider[Dynamic[m], {1, 8, 1}, Appearance -> "Labeled"]}], 
     RadioButtonBar[
      Dynamic[ct], {5 -> \[DoubleStruckCapitalZ], 
       1 -> \[DoubleStruckCapitalQ]}]}], 
   Dynamic[pc = 
     Function[g, Rationalize[g, ct*0.1]] /@ 
      RandomReal[{-10, 10}, n + 1]], 
   Dynamic[qc = 
     Function[g, Rationalize[g, ct*0.1]] /@ 
      RandomReal[{-10, 10}, m + 1]], 
   Dynamic@Grid[{pc, qc}, Frame -> All]}]]

```

 ![6646Capture.JPG](https://global.discourse-cdn.com/wolfram/original/2X/2/2bfc7932c19dcdc029fddbfc6c4e8a75acd864c2.jpeg)

---

<div class="post-metadata">

**Author:** ![jorgeman49](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@jorgeman49](https://community.wolfram.com/u/jorgeman49)\
**Post date:** [July 13, 2017, 3:08am UTC](https://community.wolfram.com/t/list-layout-using-grid/10921/9 "2017-07-13T03:08:19Z")

</div>

Yes, it works great.

But if I change the commas by semicolons it does not work.

Is there any way to hide the intermediate results in the notebook? I mean just show the Grid

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [July 13, 2017, 6:41am UTC](https://community.wolfram.com/t/list-layout-using-grid/10921/10 "2017-07-13T06:41:13Z")

</div>

How about using `Manipulate`:

```
numberList[n_, ct_] := 
  Rationalize[RandomReal[{-10, 10}, n + 1], ct*0.1];
Manipulate[With[{pc = numberList[n, ct], qc = numberList[m, ct]},
  Column[{pc, qc, Grid[{pc, qc}, Frame -> All]}]],
 {n, 1, 8, 1},
 {m, 1, 8, 1},
 {{ct, 5}, {5 -> \[DoubleStruckCapitalZ], 
   1 -> \[DoubleStruckCapitalQ]}}]

```

---

<div class="post-metadata">

**Author:** ![lvveen](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/lvveen/32/4003_2.png) [@lvveen](https://community.wolfram.com/u/lvveen)\
**Post date:** [July 13, 2017, 12:16pm UTC](https://community.wolfram.com/t/list-layout-using-grid/10921/11 "2017-07-13T12:16:40Z")

</div>

Hi Gorni,  
Yes you are right. I believe Manipulate is the way to go also with all the other stuff Jorge wants to do around it.

---

<div class="post-metadata">

**Author:** ![jorgeman49](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@jorgeman49](https://community.wolfram.com/u/jorgeman49)\
**Post date:** [July 14, 2017, 1:42am UTC](https://community.wolfram.com/t/list-layout-using-grid/10921/12 "2017-07-14T01:42:48Z")

</div>

Hello guys, Gianluca’s code does the job.  
I confess that I tried to avoid using Manipulate, for me it is very opaque and esoteric.  
I still wonder why if I replace commas with semicolons the former code stops working  
Semicolons are used to avoid the outs, are they?

Last question, I promise, how can I place the radio button to the right of the sliders?

Thank you very much for your help

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [July 14, 2017, 8:44am UTC](https://community.wolfram.com/t/list-layout-using-grid/10921/13 "2017-07-14T08:44:09Z")

</div>

I think `Dynamic` triggers only when displayed. With

```
Clear[a];
Dynamic[a = 1];
Dynamic[a]

```

the command a=1 has no effect, because it is not displayed. Compare with

```
Clear[a];
Dynamic[a = 1]
Dynamic[a]

```

I often get confused too.

---

<div class="post-metadata">

**Author:** ![jorgeman49](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@jorgeman49](https://community.wolfram.com/u/jorgeman49)\
**Post date:** [July 14, 2017, 7:49pm UTC](https://community.wolfram.com/t/list-layout-using-grid/10921/14 "2017-07-14T19:49:52Z")

</div>

The example is revealing.  
That is a side effect and functional programming languages should not suffer from that. It is one of its main characteristics.

I will abuse your patience one more time, in Manipulate, can I arrange the controls in a row instead of columns?

---

<div class="post-metadata">

**Author:** ![shenghuiy](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/shenghuiy/32/36073_2.png) [@shenghuiy](https://community.wolfram.com/u/shenghuiy)\
**Post date:** [July 15, 2017, 4:23am UTC](https://community.wolfram.com/t/list-layout-using-grid/10921/15 "2017-07-15T04:23:29Z")

</div>

you may follow [this link](https://stackoverflow.com/questions/6299060/control-placement-using-manipulate-in-mathematica) , like

```
Manipulate[Plot[Sin[a x + b], {x, 0, 6}], Row[{Control@{a, 1, 4}, Control@{b, 0, 10}}]]

```

vs

```
Manipulate[Plot[Sin[a x + b], {x, 0, 6}], {a, 1, 4}, {b, 0, 10}]

```

---

<div class="post-metadata">

**Author:** ![jorgeman49](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@jorgeman49](https://community.wolfram.com/u/jorgeman49)\
**Post date:** [July 15, 2017, 8:20pm UTC](https://community.wolfram.com/t/list-layout-using-grid/10921/16 "2017-07-15T20:20:30Z")

</div>

Thanks Shenguhi,  
I used Row [.] but not Control [.]  
Now it works
