title: weird behaviour of plot_ly in R, if using for loop to create dynamic number of lines
body: <p>I am trying to plot multiple lines, using R and plot_ly in combination with add_trace. If I use the following code,it works like expected:</p>
  
  <pre><code>df &lt;- data.frame(x=c(1,2,3), y=c(2,4,5), y=c(4,1,3))
  p &lt;- plot_ly(mode="lines", type="scatter")
  p &lt;- add_trace(p, x=~df[,1], y=~df[,2])
  p &lt;- add_trace(p, x=~df[,1], y=~df[,3])
  p
  </code></pre>
  
  <p>and gives <a href="https://i.stack.imgur.com/o3JZK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o3JZK.png" alt="this image"></a></p>
  
  <p>If I try to use a for-loop instead like this, it does not work:</p>
  
  <pre><code>df &lt;- data.frame(x=c(1,2,3), y=c(2,4,5), y=c(4,1,3))
  p &lt;- plot_ly(mode="lines", type="scatter")
  for(i in 1:2)
  {
    p &lt;- add_trace(p, x=~df[,1], y=~df[,i])
  }
  p
  </code></pre>
  
  <p>which gives me only a singleline (actually the later one) <a href="https://i.stack.imgur.com/vk9wl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vk9wl.png" alt="here"></a></p>
  
  <p>May anybody explain me please, what happens here and how to fix the 2nd version?
  Thanks</p>