如何在 dash-leaflet 中制作交互式世界地图?

How can I make an interactive world map in dash-leaflet?

我正在尝试从 dash-leaflet 文档中复制 this example,但适用于世界各国而不是美国各州。但是,当我 运行 我机器上文档中的代码时,我在输出视觉中看不到蓝色状态边框。

我认为这是因为我在本地没有正确的 geojson 数据,所以我从 here 下载了一些国家边界 GeoJSON 数据,但我不清楚如何获得 dl.GeoJSON 函数以利用该数据。我怎样才能让国家边界以与链接示例中各州相同的方式显示在世界地图上?

您应该将 GeoJSON 组件的 url 属性 设置为指向您想要可视化的数据。对于您 link 中显示的所有国家/地区,代码将遵循

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()