title: Exporting PNG files from Plotly in R
body: <p>How can I export a Plotly chart as a image from R using code? (Not using the export button on the chart).</p>
  
  <p>For example, this code from the Plotly site, create this chart:</p>
  
  <pre><code>library(plotly)
  set.seed(100)
  d &lt;- diamonds[sample(nrow(diamonds), 1000), ]
  plot_ly(d, x = carat, y = price, text = paste("Clarity: ", clarity),
          mode = "markers", color = carat, size = carat)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/qR51F.png" rel="noreferrer"><img src="https://i.stack.imgur.com/qR51F.png" alt="plotly chart"></a></p>
  
  <p>How can I save it as a image?</p>
  
  <p>The official site has <a href="https://plot.ly/python/static-image-export/" rel="noreferrer">this material</a> in python, but I didn't find something similar in R.</p>