How to use a local GeoJSON file (world_110m.json) with Plotly in PySide6 to prevent external fetching?

I’m trying to display a choropleth map using Plotly and PySide6. I want to ensure that all resources, including world_110m.json, are loaded locally and not fetched from the CDN. I already have a custom GeoJSON file (map1.geojson) and the required world_110m.json file stored locally.
Here’s the code I’m using:

import sys
from PySide6.QtWidgets import QApplication
from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtCore import QUrl
from pathlib import Path
import plotly
import plotly.graph_objs as go
import json

sys.argv.append("--disable-web-security")
app = QApplication(sys.argv)

# Load the GeoJSON file
geojson_path = Path(__file__).resolve().parent / 'map1.geojson'
with open(geojson_path, 'r') as f:
    geojson_data = json.load(f)

# Create the choropleth map
fig = go.Figure(go.Choropleth(
    geojson=geojson_data,
    locations=[feature['properties']['region'] for feature in geojson_data['features']],
    z=[1 for _ in geojson_data['features']],  
    hoverinfo='location+z',
    colorbar_title="Values"
))

# Set layout to configure the map appearance
fig.update_layout(
    geo=dict(
        visible=True,
        showland=True,
        landcolor='rgb(243, 243, 243)',
        projection_type="mercator",
        showframe=False,
    ),
    margin={"r": 0, "t": 0, "l": 0, "b": 0},
    width=800,
    height=600
)

# Get the directory of the current script to load the local JS
CURRENT_DIRECTORY = Path(__file__).resolve().parent
local_js_url = QUrl.fromLocalFile(CURRENT_DIRECTORY / "plotly-latest.min.js").toString()

# HTML content with local plotly JS
raw_html = '<html><head><meta charset="utf-8" />'
raw_html += f'<script src="{local_js_url}"></script></head>'
raw_html += '<body>'
raw_html += plotly.offline.plot(fig, include_plotlyjs=False, output_type='div')
raw_html += '</body></html>'

# Create the QWebEngineView and load the HTML
view = QWebEngineView()
view.setHtml(raw_html, QUrl.fromLocalFile(CURRENT_DIRECTORY))  # baseUrl to resolve resources
view.show()

sys.exit(app.exec())

Problem:
When I run this code, Plotly tries to fetch the world_110m.json file from an external CDN (https://cdn.plot.ly/world_110m.json) and throws the following error:

js: Uncaught (in promise) Error: unexpected error while fetching topojson file at https://cdn.plot.ly/world_110m.json

I want to:

  1. Prevent Plotly from fetching the world_110m.json file from the CDN.
  2. Load the world_110m.json file from my local directory instead.

How can I modify the code to ensure Plotly uses the local world_110m.json file for the map background instead of fetching it from the internet? Is there a way to explicitly provide the file path or bypass this default behavior?

Additional Information:
I’ve come across a solution that involves setting up a Flask app to serve the world_110m.json file locally. However, this requires setting up a web server, which adds complexity (especially for someone unfamiliar with Flask or server configuration).

Is there a more direct method to accomplish this without setting up a web server? For example, can Plotly access the world_110m.json file directly from the filesystem or through a simpler mechanism?

New contributor

Voice is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật