2
$\begingroup$

Running

Dynamic[Refresh[Import["foo.json"], UpdateInterval->1]]

or

json := Import["foo.json"]

then

Dynamic[Refresh[json, UpdateInterval -> 1]]

do not update as expected!

I can evaluate json manually and get the current json in the file, but if I change the contents of the file, the output of Dynamic remains static.

Is there a way to achieve this sort of thing?

$\endgroup$
1
  • $\begingroup$ Try Dynamic[Refresh[json, TrackedSymbols :> {}, UpdateInterval -> 1]] $\endgroup$ Mar 16, 2015 at 21:51

1 Answer 1

2
$\begingroup$

This can be done with Clock. The following will import foo.json every 5 seconds.

With[{update = 5},
  Dynamic[{foo = Import["~/Desktop/foo.json"], 
           Clock[{1, update, update}, update]}]]
$\endgroup$
3
  • $\begingroup$ This worked. Thanks! $\endgroup$
    – epylar
    Mar 16, 2015 at 19:56
  • $\begingroup$ But why is UpdateInterval not working? $\endgroup$
    – VividD
    Sep 14, 2015 at 16:01
  • $\begingroup$ The update interval of 5 sec. works as expected in the code I posted in this answer, so I don't understand what you asking? $\endgroup$
    – m_goldberg
    Sep 14, 2015 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.