title: Why am I getting an Uncaught ReferenceError: Plotly is not defined
body: <p>I am getting an <code>Uncaught ReferenceError: Plotly is not defined</code> error when my page loads. The following code is beneath my div element where the plot is rendered, but on the line <code>Plotly.newPlot('myDiv', dataPlot, layout);</code> within the <code>socket.on</code> listener is where this error is being thrown.</p>
  
  <pre><code>var dataPlot = [{
      x: ['a', 'b', 'c', 'd'],
      y: [0, 0, 0, 0],
      type: 'bar'
  }];
  
  var layout = {
      autosize: false,
      width: 500,
      height: 500,
      margin: {
          l: 50,
          r: 50,
          b: 100,
          t: 100,
          pad: 4
      }
  };
  
  // Listener, whenever the server emits 'updatechat', this updates the chat body
  socket.on('updatechat', function (username, data) {
      $('#conversation').append('&lt;b&gt;'+username + ':&lt;/b&gt; ' + data + '&lt;br&gt;');
      if (data ==='a'){
          dataPlot[0]['y'][0]++;
      } else if (data === 'b'){
          dataPlot[0]['y'][1]++;
      } else if (data === 'c'){
          dataPlot[0]['y'][2]++;
      } else if (data === 'd'){
          dataPlot[0]['y'][3]++;
      }
      Plotly.newPlot('myDiv', dataPlot, layout);
  });
  
  $("#clearplot").click(function() {
      var dataPlot = [{
      x: ['a', 'b', 'c', 'd'],
      y: [0, 0, 0, 0],
      type: 'bar'
      }]
      Plotly.newPlot('myDiv', dataPlot, layout);
  });
  </code></pre>
  
  <p>I have included <code>&lt;script src="https://cdn.plot.ly/plotly-latest.min.js"&gt;&lt;/script&gt;</code> in the head of my HTML5 document, and the <code>Plotly.newPlot('myDiv', dataPlot, layout);</code> within my <code>clearplot</code> function is working just fine. Why is there an error only in the <code>updatechat</code> listener?</p>
  
  <p><strong>EDIT</strong>
  I figured out the issue. The issue was that this code is embedded in an Angular app, so I just had to include the <code>&lt;script src="https://cdn.plot.ly/plotly-latest.min.js"&gt;&lt;/script&gt;</code> within the head of the template HTML file, not the local HTML file.</p>