<% if @embedded %>
  <script>
  requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min'] }})
  if(!window.Plotly) {{require(['plotly'], function(plotly) {window.Plotly=plotly})}}
  </script>
<% else %>
  <script>
  <%= LOCAL_PLOTLY_JS %>
  </script>
<% end %>

<div id="<%= @id %>" style="height: 100%; width: 100%;" class="plotly-graph-div"></div>

<script>
require(["plotly"], function(Plotly) {
  window.PLOTLYENV=window.PLOTLYENV || {}
  window.PLOTLYENV.BASE_URL='https://plot.ly'

  Plotly.newPlot(
    '<%= @id %>',
    <%= @data.to_json %>,
    <%= @layout.to_json %>,
    <%= @config.to_json %>
  )

  window.addEventListener('resize', function() {
    Plotly.Plots.resize(document.getElementById('<%= @id %>'))
  })
})
</script>
<% if @embedded %>
  <script>
  requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min'] }})
  if(!window.Plotly) {{require(['plotly'], function(plotly) {window.Plotly=plotly})}}
  </script>
<% else %>
  <script>
  <%= LOCAL_PLOTLY_JS %>
  </script>
<% end %>

<div id="<%= @id %>" style="height: 100%; width: 100%;" class="plotly-graph-div"></div>

<script>
<% if @embedded %> require(["plotly"], function(Plotly) { <% end %>
  window.PLOTLYENV=window.PLOTLYENV || {}
  window.PLOTLYENV.BASE_URL='https://plot.ly'

  Plotly.newPlot(
    '<%= @id %>',
    <%= @data.to_json %>,
    <%= @layout.to_json %>,
    <%= @config.to_json %>
  )

  window.addEventListener('resize', function() {
    Plotly.Plots.resize(document.getElementById('<%= @id %>'))
  })
<% if @embedded %> }) <% end %>
</script>
Use require.js only when embedded in Ruby
Use require.js only when embedded in Ruby
