Since we’re getting real-time data from our weather API, let’s update our weather graph regularly to see how the temperature is changing during the day.

Go to ‘Design’ view in the Form Editor and drop a ‘Timer’ Timer icon component onto the page.

We can set the interval property of our timer - that’s how often our Timer will ‘tick’. We’ll then call our get_weather_data function each time the Timer ‘ticks’.

The default interval is 0.5 seconds – let’s slow that down to 2 seconds. Click on the Timer, and in the Properties panel on the right, change the interval from 0.5 to 2 seconds.

Gif of adding timer to app

Next, we want to call our get_weather_data server function each time our Timer ticks.

We’ll use Events for this.

Set up an event handler

Anvil components can raise events. For example, when a Timer ticks, it raises the ‘tick’ event.

Click on your Timer, and scroll to the bottom of the Properties Panel. You’ll see a list of events for the Timer.

Click the blue arrows next to ‘tick’.

You’ll see a timer_1_tick method. Edit it to look like this:

def timer_1_tick(self, **event_args):
  """This method is called every [interval] seconds. Does not trigger if [interval] is 0."""
  with anvil.server.no_loading_indicator:

Run your app

Click the Run button, and you’ll see that your temperature graph is displaying real-time data from OpenWeatherMap’s REST API. Fabulous!

Screenshot of dashboard with four graphs

We’ve built a dashboard with data from four different sources and displayed on the web, all with nothing but Python.