Python Forum
Read plotly-latest.min.js from local - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Read plotly-latest.min.js from local (/thread-30996.html)



Read plotly-latest.min.js from local - issac_n - Nov-17-2020

Hi all,

I would like to plot charts without using internet and I downloaded js file and put same as py file together.
I Using 3 methods to the js file.

only Method 2 is working, but I want to run the code without internet; where is my mistake?
#raw_html += '<script src="{}"></script></head>'.format(local) #method 1 NOK
#raw_html += '<script src="https://cdn.plot.ly/plotly-latest.min.js"></script></head>' #method 2 ok
raw_html += '<script type="text/javascript" src="file:///C:/Users/User/Desktop/testOfflineChart/plotly-latest.min.js"></script></head>' # method 3 NOK
I am running the code in Win 10 , python 3.7 Wall
full code as below;
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtCore import QDir, QUrl

import plotly
import plotly.graph_objs as go

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

x1 = [10, 3, 4, 5, 20, 4, 3]
trace1 = go.Box(x = x1)
layout = go.Layout(showlegend = True)
data = [trace1]

fig = go.Figure(data=data, layout = layout)

path = QDir.current().filePath('plotly-latest.min.js') 
local = QUrl.fromLocalFile(path).toString()
print(local)
raw_html = '<html><head><meta charset="utf-8" />'
#raw_html += '<script src="{}"></script></head>'.format(local) #method 1 NOK
#raw_html += '<script src="https://cdn.plot.ly/plotly-latest.min.js"></script></head>' Method 2 #ok
raw_html += '<script type="text/javascript" src="file:///C:/Users/User/Desktop/testOfflineChart/plotly-latest.min.js"></script></head>' # method 3 NOK
raw_html += '<body>'
raw_html += plotly.offline.plot(fig, include_plotlyjs=False, output_type='div')
raw_html += '</body></html>'

view = QWebEngineView()
view.setHtml(raw_html)
view.show()
print(local)
sys.exit(app.exec_())



RE: Read plotly-latest.min.js from local - issac_n - Nov-18-2020

anyone help?