We can create a real-time monitor for a variable like this:
CreatePalette@Panel@Row[{"x = ", Dynamic[x]}]
(This is more interesting and useful if x
happens to be something like $Assumptions
. It's so easy to set a value and then forget about it.)
Unfortunately this stops working if the kernel is re-launched (Quit[]
, then evaluate something). The palette won't show changes in the value of x
any more.
Is there a way to do this so it keeps working even across kernel sessions? I find myself restarting the kernel quite often. (If the resulting palette causes the kernel to be automatically started after Quit
that's fine.)
Update: As mentioned in the comments, it turns out that the palette ceases working only if we quit by evaluating Quit[]
. When using Evaluation -> Quit Kernel -> Local
, it will keep working.
I can only guess, because on my Ubuntu here the situations seems buggy. The trick with the Quit from the menu like Leonid suggested did not work here. Another one is: on a fresh Mathematica session with only one notebook open:
Dynamic[x]
x = 1
Dynamic[x]
x = 2
gives as expected
2
1
2
2
Typing in the next line Quit
, evaluating and typing then x=3
updates only the first of the Dynamic[x].
Nevertheless, have you checked the command
Internal`GetTrackedSymbols[]
This gives not only the tracked symbols but additionally some kind of ID where the dynamic content belongs. If you can find out, what exactly these numbers are and investigate in the other functions you find in the Internal context, you may be able to add your palette Dynamic-content manually after restarting the kernel.
I thought I had something like that with
Internal`SetValueTrackExtra
but I'm currently not able to reproduce the behavior.
@halirutan's answer jarred my memory...
Have you ever come across: Experimental/ref/ValueFunction
? (documentation address)
Although the documentation contains no examples, the 'more information' section provides the following tidbit:
The assignment
ValueFunction[symb] = f
specifies that wheneversymb
gets a new valueval
, the expressionf[symb,val]
should be evaluated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With