Вот тестовый код, который в настоящее время работает с CDN:
Код: Выделить всё
import sys
import plotly.graph_objects as go
from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout
from PySide6.QtWebEngineWidgets import QWebEngineView
import plotly.offline as po
class GraphWidget(QWebEngineView):
def __init__(self):
super().__init__()
# Create a random graph (scatter plot example)
fig = go.Figure(data=go.Scatter(x=[1, 2, 3, 4, 5], y=[5, 4, 3, 2, 1], mode='lines+markers'))
# Convert the figure to HTML
raw_html = """
body {{
margin: 0;
background-color: rgb(44, 49, 60); /* Ensure the body matches the dark theme */
}}
.plot-container {{
width: 100%; /* Ensure plot takes full width */
height: 100%; /* Ensure plot takes full height */
}}
{}
""".format(po.plot(fig, include_plotlyjs=False, output_type='div'))
# Set the HTML for the graph in the QWebEngineView
self.setHtml(raw_html)
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Plotly Graph in GUI')
self.setGeometry(100, 100, 800, 600)
# Create the Graph widget
self.graph_widget = GraphWidget()
# Set the layout
layout = QVBoxLayout(self)
layout.addWidget(self.graph_widget)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec())
Код: Выделить всё
Может ли кто-нибудь помочь мне изменить этот код? загрузитьplotly-latest.min.js по локальному пути вместо использования CDN? Будем очень признательны за любые советы по решению этой проблемы.
Подробнее здесь: https://stackoverflow.com/questions/792 ... -webengine
Мобильная версия