Reputation: 23
I'm trying to replicate this example from the dash-leaflet documentation, but for world countries instead of US states. However, when I run the code from the documentation on my machine I don't see the blue state borders in the output visual.
I figured this was because I don't have the right geojson data locally, so I downloaded some country border GeoJSON data from here but it's unclear to me how to get the dl.GeoJSON function to make use of that data. How can I get country borders to show up on the world map in the same way the states do in the linked example?
Upvotes: 0
Views: 1543
Reputation: 6024
You should set the url
property of the GeoJSON
component to point to the data that you want to visualize. For all countries as shown in your link, the code would be along the lines of
import dash_leaflet as dl
from dash import Dash
# An url pointing to the data that you want to show.
url = "https://pkgstore.datahub.io/core/geo-countries/countries/archive/23f420f929e0e09c39d916b8aaa166fb/countries.geojson"
# Create example app.
app = Dash()
app.layout = dl.Map(children=[dl.TileLayer(), dl.GeoJSON(url=url)],
style={'width': '100%', 'height': '50vh', 'margin': "auto", "display": "block"})
if __name__ == '__main__':
app.run_server()
Upvotes: 1