Is it possible to import an external script in templates?

I'm trying to import an external graphic into my node-red project, but without success, because the script I'm trying to import is not loading.

This is my script:

<!DOCTYPE html>
<html>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<body>

<div id="myPlot" style="width:100%;max-width:700px"></div>

<script>

var status = msg.payload[0].status;

var xArray = [50,60,70,80,90,100,110,120,130,140,150];
var yArray = [7,8,8,9,9,9,10,11,14,14,15];

// Define Data
var data = [{
  x: xArray,
  y: yArray,
  mode:"lines"
}];

// Define Layout
var layout = {
  xaxis: {range: [0, 200], title: "Ping"},
  yaxis: {range: [0.0, 23.59], title: "Hour"},  
  title: "Histórico de Ping"
};

// Display using Plotly
Plotly.newPlot("myPlot", data, layout);
</script>

</body>
</html>

Is there a workaround for importing scripts or is it not possible?

A Ui-Template should not have html or head or body tags.

Even if they were required you have the CDN outside of head and body.

Get rid of the html and body tags. Also, it goes without saying, a page that uses a cdn will require internet access on the machine it is being viewed.

The alternative is to host this js file on your node-red server. Search forum and read docs for adding static folder

A okay, got it. Thanks again

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.