Daanalytics

Plotting F1 Circuit Locations into a map on Streamlit using Folium

In my last blogpost I showed how to plot F1 Circuit Locations into a map using Folium. This was a very static way to plot the F1 Circuit Locations either for the World, Europe or France. These options were hardcoded in the notebook and showed after each other.

Next step would be to make the solution more interactive, using Streamlit. The idea is to switch between the World, a possible Continent and a possible Country. Check the video below.

Streamlit App – Plotting F1 Circuit Locations into a map on Streamlit using Folium

To make the above possible, I have taken the code from the last blogpost. As I presented at BUILD.local last month, it’s relatively straight forward to get started with Streamlit. There are a few things to take into consideration.

  1. To make things work in Streamlit (compared to the previous notebook) the necessary additional Python libraries have to be installed and imported.
To make things work in Streamlit (compared to the previous notebook) the necessary additional Python libraries have to be installed and imported.
  1. Streamlit Page settings come before all the other logic
Streamlit Page settings come before all the other logic

Compared to the previous blogpost, Streamlit should include some more interactivity. Therefore the logic has to be changed to be able to select and filter different values.

I used a s Streamlit-statement; ‘st.sidebar’ to put some controls in the Sidebar of the Streamlit application.

  1. Adding filter(s) – Radio button to select between the World, a possible Continent and a possible Country
Adding filter(s) - Radio button to select between the World, a possible Continent and a possible Country
  1. Load data based on the selected ‘Map Type’
Load data based on the selected 'Map Type'
  1. Create Datasets, based on the selected ‘Map Type’; One query for the ‘World’, selections based on this query for ‘Continent’ and ‘Country’.
  1. Show a different ‘Select Box’ based on the selected ‘Map Type’
  1. Filter Data based on the selection per ‘Map Type’
Filter Data based on the selection per 'Map Type'
  1. Create Data Set for the Folium map not be drawed based on the selection per ‘Map Type’
  1. Draw the Folium Map based on the selection per ‘Map Type’

Note: Zoom the Folium Map based on the ‘Latitude / Longitude’-edges (Left Down and Top Right) of the selected circuits.

Zoom the Folium Map based on the 'Latitude / Longitude'-edges (Left Down and Top Right) of the selected circuits.
  1. Finally putting everything together and show the final Streamlit application with the Folium map, showing the circuits in the selected area.
Finally putting everything together and show the final Streamlit application with the Folium map, showing the circuits in the selected area.

Closing Statements

The previous example provided the steps to plot F1 Circuit Locations into a map using Folium; a Python library used for visualizing Geospatial Data. In this example I added some interactivity with Streamlit. Please check it out and let me know what you think. The code is onย Github.

I also tried to set things up in Streamlit Cloud. Unfortunately at time of writing I have ran into issues, which I am unable to solve, yet. I am currently trying via some experts on the forum.

Till next time.

Daan Bakboord โ€“ DaAnalytics

Bekijk ook:

Snowflake DSH Team 2025

๐—œ๐—ป๐˜๐—ฟ๐—ผ๐—ฑ๐˜‚๐—ฐ๐—ถ๐—ป๐—ด ๐˜๐—ต๐—ฒ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฑ ๐—ฆ๐—ป๐—ผ๐˜„๐—ณ๐—น๐—ฎ๐—ธ๐—ฒ โ„๏ธ ๐——๐—ฎ๐˜๐—ฎ ๐—ฆ๐˜‚๐—ฝ๐—ฒ๐—ฟ๐—ต๐—ฒ๐—ฟ๐—ผ๐—ฒ๐˜€! ๐Ÿš€

Last week theย Snowflake โ„๏ธ Data Superhero Class of 2025ย has beenย announcedย byย Amilee Alesna. I am one the 105 worldwide Data Superheroes recognized by Snowflake. Looking back at my first avatar, created by Francis Mao, I realized that I am an OG Data Superhero since 2018.

Lees verder ยป

Snowflake BUILD Amsterdam – Cortex Analyst Hands-On Lab

Last Wednesday I had the privilege to organize and give a Snowflake BUILD Hands-On Lab. Snowflake BUILD is Snowflakeโ€™s yearly event for Developers, Data Scientists, Data Engineers, and all Data Professionals full โ€œof exclusive product announcements, โ€œhow toโ€ technical sessions, and hands-on labs focused on Snowflakeโ€™s latest innovations. Learn how to build data pipelines, models and apps in the age of generative AI and LLMs.โ€

Lees verder ยป