I would like to update specific parts of a Grid
dynamically in different ways. Consider the following toy example: I have two rows: one must be updated one-by-one (a, b, c), as these symbols depend on different triggers; the second row depends on one single trigger (show) that allows displaying/hiding some data.
Now I know that I can wrap the whole Grid
structure into Dynamic
, and even specify which symbols to track, thus this example does what I want:
Checkbox[Dynamic[show]]
test = {0, 0};
Dynamic[Grid[{{Dynamic@a, Dynamic@b, Dynamic@c},
If[show, Prepend[test, "test:"], {}]}, Frame -> All],
TrackedSymbols :> {show}]
Though for certain reasons I would like to have a locally specified Dynamic
, that is only applied to the second row of the Grid
.
For those who are wondering what ungodly situation would it be, just imagine the followings: show
is used in any of a
, b
or c
, and these I do NOT want to update when show
is changing, their changes depend on other triggers. Why not remove then show
from the symbols of the first row? Imagine, I can't, as show
is present in a function that is used in a
, b
or c
, and this function I cannot access easily.
Of course wrapping the first argument of If
into Dynamic
won't help here, as the Grid
itself or any of its cells won't become dynamic:
Grid[{
{Dynamic@a, Dynamic@b, Dynamic@c},
If[Dynamic@show, Prepend[test, "test:"], {}]
}, Frame -> All]
Furthermore, wrapping a row into Dynamic
makes the given row invalid, as it does not have head List
anymore:
Grid[{
{Dynamic@a, Dynamic@b, Dynamic@c},
Dynamic@If[show, Prepend[test, "test:"], {}]
}, Frame -> All]
Mapping Dynamic
over the row does not work either because show
is not updated dynamically:
Grid[{
{Dynamic@a, Dynamic@b, Dynamic@c},
Dynamic /@ If[show, Prepend[test, "test:"], {}]
}, Frame -> All]
Also, wrapping Dynamic[If[...]]
around list members work, but now I have to evaluate If
3 times instead of just 1.
Grid[{
{Dynamic@a, Dynamic@b, Dynamic@c},
Dynamic[If[show, #, ""]] & /@ Prepend[test, "test:"]
}, Frame -> All]
Would like to know if there is any solution to overcome this particular problem by locally applying a Dynamic
wrapper on a row.
show
3. but only the second row must be updated whenshow
changes. Did I get it right? – HelotIf
undesirable? Is the test inIf
expensive? We might come up with something that evaluates the test a single time and stores the result into a variable which then controls the threeIf
s. I believe if you wrap the whole thing then you can't avoid updating ofa,b,c
, but I'm not sure! – Helot