Give me an app that displays a map of europe, when hovering over a country it displays info about that country. Colourmap the visualisation by GDP
To upload files, please first save the app
import streamlit as st
import pandas as pd
import geopandas as gpd
import plotly.express as px
st.title("European Countries GDP Map")
# Load Europe GeoJSON data
@st.cache_data
def load_europe_data():
# NOTE: Using corsproxy.io because we're in a WASM environment. If running locally,
# you can remove the corsproxy.io prefix.
url = "https://corsproxy.io/?https://raw.githubusercontent.com/leakyMirror/map-of-europe/master/GeoJSON/europe.geojson"
europe = gpd.read_file(url)
return europe
# Create sample GDP data (2021 estimates, in billions USD)
gdp_data = {
'NAME': [
'Germany', 'United Kingdom', 'France', 'Italy', 'Spain',
'Netherlands', 'Switzerland', 'Poland', 'Sweden', 'Belgium',
'Austria', 'Ireland', 'Norway', 'Denmark', 'Finland',
'Portugal', 'Czech Republic', 'Romania', 'Greece', 'Hungary'
],
'GDP': [
4223, 3108, 2940, 2100, 1427,
1012, 752, 674, 627, 578,
477, 498, 482, 395, 297,
253, 282, 284, 216, 182
]
}
# Create DataFrame
gdp_df = pd.DataFrame(gdp_data)
# Load and merge data
europe = load_europe_data()
europe = europe.merge(gdp_df, how='left', on='NAME')
# Create choropleth map using Plotly
fig = px.choropleth(
europe,
geojson=europe.geometry,
locations=europe.index,
color='GDP',
hover_name='NAME',
hover_data={'GDP': True},
color_continuous_scale='Viridis',
labels={'GDP': 'GDP (Billions USD)'},
)
# Update layout
fig.update_geos(
fitbounds="locations",
visible=False,
)
fig.update_layout(
title_text='European Countries GDP Map',
title_x=0.5,
margin={"r": 0, "t": 30, "l": 0, "b": 0},
height=600,
)
# Display the map
st.plotly_chart(fig, use_container_width=True)
# Add information section
st.markdown("""
### About this visualization
- The map shows GDP values for European countries (2021 estimates)
- GDP values are in billions of USD
- Hover over countries to see specific details
- Darker colors indicate higher GDP values
- Some countries may not have GDP data available
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?