Getting Started with Plotly for R
As of version 2.0 (November 17, 2015), graphs created with the
plotly R package are rendered locally through the
Download from CRAN
install.package() function to install the
plotly R package from CRAN. This version may not be the absolute latest version, so we recommend downloading from Github using the instructions below if you can.
Download from GitHub
Alternatively, you can install the latest development version of
plotly from GitHub via the
devtools R package:
RStudio users should ensure that they are using the latest RStudio release in order to ensure compatibility with the
htmlwidgets R package.
By default, the
plotly R package runs locally in your web browser or in the
library(plotly) fig <- plot_ly(midwest, x = ~percollege, color = ~state, type = "box") fig
Simply printing the plot object will render the chart locally in your web browser or in the
Graphs created with the
plotly R package are interactive!
Click on legend entries to hide/show traces, click-and-drag on the chart to zoom, double-click to autoscale, shift-and-drag to pan.
What About Dash?
Learn about how to install Dash for R at https://dashr.plot.ly/installation.
Everywhere in this page that you see
fig, you can display the same figure in a Dash for R application by passing it to the
figure argument of the
Graph component from the built-in
dashCoreComponents package like this:
library(plotly) fig <- plot_ly() # fig <- fig %>% add_trace( ... ) # fig <- fig %>% layout( ... ) library(dash) library(dashCoreComponents) library(dashHtmlComponents) app <- Dash$new() app$layout( htmlDiv( list( dccGraph(figure=fig) ) ) ) app$run_server(debug=TRUE, dev_tools_hot_reload=FALSE)