2
$\begingroup$

Is it possible to create interactive code in Mathematica (via EventHandler[] or Manipulate[] perhaps) that continually updates some calculation based on external data in the time when no user input is received?

As a trivial example, code that shows the current time, with seconds, continually updating, and which allows the user to click on any of the numbers to change their color.

Thank you.

$\endgroup$
  • $\begingroup$ Michael when you refer to "external data in the time when no user input is received" could you mean scheduling an import of data from an external source at either a fixed time or regular intervals? $\endgroup$ – Mike Honeychurch Dec 28 '12 at 1:23
  • $\begingroup$ Also have a look at Clock in the documentation. In fact, this question is quite unspecific. For example, do you want the updates to continue when the relevant cell is not being displayed on the screen? Dynamic doesn't permit that. What is it you're trying to achieve? What have you tried? $\endgroup$ – Jens Dec 28 '12 at 5:16
  • $\begingroup$ Responding to the first comment above -- yes, in practice, this will involve a scheduled import of third party data (actually, essentially continuous import of data that changes very frequently). $\endgroup$ – Michael Stern Dec 28 '12 at 13:04
6
$\begingroup$

Yes, it is possible. Have you read the tutorials about Dynamic? Here is a simple example of a continuously updated time which changes color on Mouseover

Dynamic[Refresh[
  Mouseover[DateString[],Style[DateString[],20,Blue]],
UpdateInterval->1]]

Here the slightly more complex example with two buttons.

DynamicModule[{bold=False,blue=False},
  Column[{
    Button["Toggle Bold",bold=!bold],
    Button["Toogle Blue", blue=!blue],
    Dynamic[Refresh[
      Style[DateString[],If[blue,Blue,Black],If[bold,Bold,Plain]],UpdateInterval->1]
    ]
  }]
]

Mathematica graphics

$\endgroup$
  • $\begingroup$ That is helpful. Can you show how to do it with buttons above the time, each representing a different action (say, a different color to change to time to when clicked?) $\endgroup$ – Michael Stern Dec 28 '12 at 0:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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