Let's create simple function:
SetAttributes[h, HoldFirst];
h[data_] := Dynamic[Grid[data], TrackedSymbols :> {data}]
test = RandomReal[1, {2, 2}];
h[test]
Now you can evaluate somewhere else:
test = RandomReal[1, {2, 2}];
And our grid will be updated. However if it is only a part of huge structure: (here not so huge ofc)
test2 = RandomReal[1, {2, 2, 2}];
h[ test2[[1]] ]
Evaluating test2 = RandomReal[1, {2, 2, 2}]
will not change anything because what's inside TrackedSymbols
is not a Symbol
.
Anticipating questions:
Yes,
TrackedSymbols
is necessary, code above is only a minimal example.No I don't want to track whole
test2
.No I don't want to split my
test2
before passing it toh
into pieces that are meant to be tracked later. I need the referrence to be clear, if I do something inside with part oftest[[1]]
thentest
will be updated. If I pass those new symbols then I will have to care about updatingtest
each time. Or maybe there is a way of dealing with this?
Do I want too much? :)
Grid
may be heavy layout that I want to recalculate only when necessary and here it would be even if you change part oftest2
that is not used inGrid
. $\endgroup$test3 := test2[[1]]
and then useh[test3]
? $\endgroup$h
there may be a procedure to changedata
so the oryginal table will not be updated. Moreover, your example will not be updated becausetest3
is not changing unless evaluated. $\endgroup$