Build a weather dashboard
Retool is great for quickly building business software but you can also use it for side projects, prototyping, etc. For example, with just a few API calls, you can build your own weather dashboard.
What you'll build
You're going to create a weather dashboard that shows the forecast and the National Weather Service (NWS) forecast discussion. The combination of standard forecast data (highs, lows, etc.) and text discussion from meteorologists makes for a well-rounded forecast.
The forecast data is provided by MyRadar, and the NWS discussion comes from the NWS API. Both the MyRadar and NWS APIs are free to use with some standard limitations.
Prerequisites
To build the weather dashboard, you need:
- A Retool account.
- A MyRadar developer account. Make sure to note down your Subscription Key after creating your account.
You can find this information later but you also need:
- The latitude and longitude of the location you want a forecast for. You can use Google Maps to search for the location, then right click the pin to get the coordinates. This guide uses Detroit, with the coordinates
42.34899378680771, -83.07695478794027
. - An NWS forecast office code. This guide uses Detroit's code (
dtx
), but if you want to find the office closest to you, click the location on this map. It opens a new page and the code is in the URL (Detroit's NWS office URL:https://www.weather.gov/dtx/
).
1. Create a MyRadar resource
Resources are how you connect your data sources to Retool.
- Navigate to
/resources
in Retool and click Create new -> Resource. - Select Rest API.
- Fill out the resource configuration page like this:
- Click Create resource and then Create an app. This opens another modal where you name the app and then click Create app.
2. Retrieve forecast data
If you don't have the latitude and longitude for your location yet, see the prerequisites section.
To retrieve forecast data:
- Create a query and name it getMyRadarForecast.
- Select the resource you just created.
- Pass the coordinates (
42.34899378680771,-83.07695478794027
) in the endpoint. - In the URL parameters section, set
units
tous
. - Click Save and run.
3. Display forecast data
The data returned is split up into timeframes (currently, minutely, hourly, and daily). This app is going to show the current weather and the hourly forecast, but you can adjust this if you want.
To display the current weather:
- Drag a Key Value component to the canvas and set Data to
{{getMyRadarForecast.data.currently}}
. - In the right panel, edit properties as needed.
To display the hourly forecast:
- Drag a Table component to the canvas and set its Data property to
{{ getMyRadarForecast.data.hourly.data }}
. - Convert the UNIX timestamp in the time column by selecting the column in the right panel, and then set Mapped value to
{{moment.unix(item).format("MM/DD/YYYY h:mm:ss A")}}
. - Adjust the table's appearance as needed.
4. Retrieve forecast discussion
If you don't have an NWS forecast office code yet, see the prerequisites section. You can also use the one in the examples (dtx
) below if you don't want to use your local office.
To retrieve the forecast discussion:
- Create a new resource query and name it
get_all_forecast_discussions
. - Set the Resource to RESTQuery (restapi).
- Set the endpoint to
https://api.weather.gov/products/types/AFD/locations/DTX
, replacingDTX
with your local office code if needed. - Click Save and run.
This query retrieves URLs for every available forecast discussion for the office. To retrieve the latest discussion:
- Duplicate the query you just created and name it
get_latest_forecast_discussion
. - Set the endpoint to
{{get_all_forecast_discussions.data['@graph']['0']['@id']}}
. - Click Save and run.
5. Display the forecast discussion
To display the forecast discussion:
- Drag a Text component to the canvas and set its value to
{{get_latest_forecast_discussion.data.productText}}
. - Forecast discussions can be long, so set the Height to fixed on the Text component and adjust it as needed.
6. Add polish
You now have all the weather data in the app, but if you want to polish things up:
- Use Text components to add headers to each part of the app.
- Rearrange the components so they fit together well.
- Edit the theme and make usability adjustments.
- Add a Button component that reruns the queries to refresh the data.
With some modifications, your dashboard might look something like this.
If you want to import the app, here's the JSON.