Show Sidebar Hide Sidebar

Using Plotly Offline in R

Plotly offline using the Plotly R client, Shiny and RStudio

  • Plotly R figures appear interactively within RStudio's graphics viewer without any calls to Plotly's server by default. This means that all plots generated in RStudio are offline. You will have to make a plotly_POST call in order to upload your plot onto the Plotly Cloud.
  • Plotly graphics in RStudio sit on top of the HTML widgets framework and use the open source javascript graphing library plotly.js.

Getting the HTML for a Plotly Graph

You could treat the viewer in RStudio as an embedded web browser. Thus it's possible to view the source of that page. What you have to do is click the export button in the viewer, and choose Save as Web Page. You will then be prompted to save the web page. Then you will be able to view the source code when viewing the plot.

An alternative method in which to get the html for your plot is to call the following command:
htmlwidgets::saveWidget(as.widget(p), "graph.html"), where p will be your plot figure. Note that you could name the html file to anything you choose.

Working with Shiny

With Shiny and Plotly you can now make data visualization interactive. What Shiny allows you to do is affect the state of your plots via widgets provided by the Shiny package or even custom widgets you write in HTML yourself. What this means is that you can interact with both the styling of the plots, as well as the data that's being plotted. Thus you can do things like filter date on the fly and have your plot reflect these changes. To get started, visit:, and for a collection of examples, checkout:

Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.