0

my code is ok when reading "plotly-latest.min.js" from online and I have save it into ".js" and put in same directory with my ".py" file. But I am fail to read from local without internet.

    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")
#sys.argv()
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)


raw_html = '<html><head><meta charset="utf-8" />'
raw_html += '<script src="https://cdn.plot.ly/plotly-latest.min.js"></script></head>' #ok

#raw_html += '<script type="text/javascript" src="file://C:/Users/User/Desktop/Python-setup test/plotly-latest.min.js"></script></head>'
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()

sys.exit(app.exec_())

now I am try to make the code below read from local

 raw_html += '<script src="https://cdn.plot.ly/plotly-latest.min.js"></script></head>'

code below not working and no errors

raw_html += '<script type="text/javascript" src="file://C:/Users/User/Desktop/Python-setup test/plotly-latest.min.js"></script></head>'
Issac_n
  • 89
  • 1
  • 2
  • 13

1 Answers1

0

Then I guess the problem is to do with the path

raw_html += '<script type="text/javascript"src="file://C:/Users/User/Desktop/Python-setup test/plotly-latest.min.js">'

Are you sure this is a valid path? And that the local version of the file actually exists there and not corrupted? Try and format a relative path to the file and see if that works.

You can also try and find the error by going to the

Inspect ->Console section on Google Chrome for example.

AzyCrw4282
  • 7,222
  • 5
  • 19
  • 35
  • I download the ".js" text from https://plotly.com/javascript/getting-started/ I download and save as ".js" from text file. and the path is valid because I can open from browser "file:///C:/Users/User/Desktop/Python-setup%20test/plotly-latest.min.js" , Notice missing "%20" in my previous code. But still not working after adding "%20" – Issac_n Nov 04 '20 at 14:35
  • Can you see if it shows any errors by following the method mentioned in the answer? – AzyCrw4282 Nov 04 '20 at 16:28
  • if I am not wrong, i didn't c any errors here. https://www.sendspace.com/file/7xh9vz https://www.sendspace.com/file/wsbxnm I am not familiar with html and java as well, so it is a hard time for me and hope u can help me on this. – Issac_n Nov 08 '20 at 06:55