Ошибка js: Uncaught ReferenceError: Plotly is not defined
Мне нужно отобразить plotly график в окне PyQt5.
Тут https://stackoverflow.com/questions/60522103/how-to-have-plotly-graph-as-pyqt5-widget на такой вопрос уже ответили.
Но после запуска скрипта оттуда выходит ошибка:
js: Uncaught ReferenceError: Plotly is not defined.
Подскажите пожалуйста, как решить эту проблему.
#pip install PyQtWebEngine
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
import plotly.express as px
class Widget(QtWidgets.QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.button = QtWidgets.QPushButton('Plot', self)
self.browser = QtWebEngineWidgets.QWebEngineView(self)
vlayout = QtWidgets.QVBoxLayout(self)
vlayout.addWidget(self.button, alignment=QtCore.Qt.AlignHCenter)
vlayout.addWidget(self.browser)
self.button.clicked.connect(self.show_graph)
self.resize(500,400)
def show_graph(self):
df = px.data.tips()
fig = px.box(df, x="day", y="total_bill", color="smoker")
fig.update_traces(quartilemethod="exclusive") # or "inclusive", or "linear" by default
self.browser.setHtml(fig.to_html(include_plotlyjs="cdn"))
#print(fig.to_html(include_plotlyjs="cdn"))
if __name__ == "__main__":
app = QtWidgets.QApplication([])
widget = Widget()
widget.show()
app.exec()
Ответы (1 шт):
Автор решения: S. Nick
→ Ссылка
У меня тоже как-то по другому ругалось.
Обновил plotly:
python.exe -m pip install --upgrade plotly
и все ok.
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
import plotly.express as px
class Widget(QtWidgets.QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.button = QtWidgets.QPushButton('Plot', self)
self.browser = QtWebEngineWidgets.QWebEngineView(self)
vlayout = QtWidgets.QVBoxLayout(self)
vlayout.addWidget(self.button, alignment=QtCore.Qt.AlignHCenter)
vlayout.addWidget(self.browser)
self.button.clicked.connect(self.show_graph)
self.resize(500,400)
def show_graph(self):
df = px.data.tips()
fig = px.box(df, x="day", y="total_bill", color="smoker")
fig.update_traces(quartilemethod="exclusive") # or "inclusive", or "linear" by default
# fig.update_traces(quartilemethod="inclusive")
self.browser.setHtml(fig.to_html(include_plotlyjs="cdn"))
#print(fig.to_html(include_plotlyjs="cdn"))
if __name__ == "__main__":
app = QtWidgets.QApplication([])
widget = Widget()
widget.show()
app.exec()
