Show Sidebar Hide Sidebar

Getting Started with Shiny and Plotly in R

Getting Started with Shiny and Plotly

New to Plotly?

Plotly's R library is free and open source!
Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode.
We also have a quick-reference cheatsheet (new!) to help you get started!

Version Check

Version 4 of Plotly's R package is now available!
Check out this post for more information on breaking changes and new features available in this version.


Plotly Graphs in Shiny

Since plotly adheres to the htmlwidgets framework, it's easy to embed plotly graphs in shiny apps. Not only does this make it easy for your plotly graphs to change dynamically according to input values, but (thanks to event_data()) it is also easy to access user events with plotly graphs! Here is a fairly basic example of accessing hover events server-side:


ui <- fluidPage(

server <- function(input, output) {

  # renderPlotly() also understands ggplot2 objects!
  output$plot <- renderPlotly({
    plot_ly(mtcars, x = ~mpg, y = ~wt)

  output$event <- renderPrint({
    d <- event_data("plotly_hover")
    if (is.null(d)) "Hover on a point!" else d

shinyApp(ui, server)

Check out our shiny gallery for more examples!