RStudio crashes when zooming in plotly

Hello, all

I am trying plotly with ggplot2 for the first time. When I run the following code and try to zoom in or out, RStudion crashes and closes down.

library(magrittr)
library(ggplot2)
library(plotly)

data(mpg)

graf <- mpg %>% 
  ggplot(aes(x=displ, y= hwy, color = factor(cyl))) +
  geom_point() 

graf <- ggplotly(graf)            
graf

I am using the latest versions of R (3.5.1), RStudio (1.1.456) and Plotly (installed from CRAN and github). I also updated all the installed packages.

The code works fine if I run it directly in R. I can zoom in and out, resize the plot, etc. In RStudio, when I try it, RStudio freezes briefly and shuts down.

Here is the session info:

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Portuguese_Brazil.1252  LC_CTYPE=Portuguese_Brazil.1252   
[3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C                      
[5] LC_TIME=Portuguese_Brazil.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plotly_4.8.0.9000 ggplot2_3.0.0    

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18      later_0.7.5       pillar_1.3.0     
 [4] compiler_3.5.1    plyr_1.8.4        bindr_0.1.1      
 [7] tools_3.5.1       digest_0.6.17     jsonlite_1.5     
[10] tibble_1.4.2      gtable_0.2.0      viridisLite_0.3.0
[13] pkgconfig_2.0.2   rlang_0.2.2       shiny_1.1.0      
[16] rstudioapi_0.7    crosstalk_1.0.0   yaml_2.2.0       
[19] bindrcpp_0.2.2    withr_2.1.2       dplyr_0.7.6      
[22] httr_1.3.1        htmlwidgets_1.2   grid_3.5.1       
[25] tidyselect_0.2.4  glue_1.3.0        data.table_1.11.6
[28] R6_2.2.2          purrr_0.2.5       tidyr_0.8.1      
[31] magrittr_1.5      promises_1.0.1    scales_1.0.0     
[34] htmltools_0.3.6   assertthat_0.2.0  xtable_1.8-3     
[37] mime_0.5          colorspace_1.3-2  httpuv_1.4.5     
[40] labeling_0.3      lazyeval_0.2.1    munsell_0.5.0    
[43] crayon_1.3.4      Cairo_1.5-9

Any help will be greatly appreciated!

Thanks for the bug report. I believe this issue is resolved with the preview release of RStudio; if you have time, can you give it a download and let me know if the issue does indeed appear to be resolved?

I'm wondering if my issue is also fixable with the preview release. I'm running plotly using event_data in a shinydashboard and it has been crashing after a few clicks. I'm on RStudio 1.1.456, it happened both on my mac and windows device. I've completely cleared my workspace and restarted. Below is the session info from my windows device. Also I've attached a sample simplified shiny app where it typically crashes after a few clicks, sometimes it won't crash until a second or third run. I'll try updating to the next RStudio version.

R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] odbc_1.1.6

loaded via a namespace (and not attached):
[1] bit_1.1-14 compiler_3.5.1 hms_0.4.2 DBI_1.0.0 tools_3.5.1 yaml_2.2.0 Rcpp_0.12.18 bit64_0.9-7
[9] blob_1.1.1 pkgconfig_2.0.1 rlang_0.2.2


library(shiny)
library(shinydashboard)
library(tidyverse)
library(plotly)
library(nycflights13)
library(shinyjs)
library(V8)

ui <-  dashboardPage(skin = "black",
                     dashboardHeader(
                       title="Test App"
                     ),
                     dashboardSidebar(sidebarMenu(id = "sidebar",
                                                  menuItem("Tab One", tabName = "tabOne", icon = icon("heartbeat")), 
                                                  menuItem("Tab Two", tabName = "tabTwo", icon = icon("warning"))
                     )),
                     dashboardBody(
                       useShinyjs(),
                       extendShinyjs(text = "shinyjs.resetClick = function() { Shiny.onInputChange('.clientValue-plotly_click-month_select', 'null'); }"),
                       tabItems(
                         tabItem(tabName = "tabOne",
                                 fluidPage(
                                   shiny::column(width = 2,
                                                 selectInput("month","Month: ", unique(nycflights13::flights$month))
                                   ),
                                   shiny::column(width = 5,
                                                 plotlyOutput("plot1")
                                   ),
                                   shiny::column(width = 5,
                                                 plotlyOutput("plot2")
                                   )
                                 )
                         ),
                         tabItem(tabName = "tabTwo",
                                 h2("Test")
                         )
                       )
                     )
)


server <- function(input, output, session) {
  
  output$plot1 <- renderPlotly({
    
    result <- nycflights13::flights %>% 
      group_by(month) %>% 
      count()
    
    plot <- result %>% 
      ggplot(aes(x = month, y = n)) + 
      geom_point(aes(text = paste0("Flight Count: ", n)), size = 1.5) +
      geom_line(size = 1) + 
      labs(x="Month",y="")
    
    plot %>% 
      ggplotly(tooltip = c("text"), source = "month_select")
    
  })
  
  output$plot2 <- renderPlotly({
    
    # Get month based on click
    event_data <- event_data("plotly_click", source = "month_select")
    print(event_data)
    
    selected_month <- input$month
    if(!is.null(event_data)) {
      selected_month <- event_data[[3]]
    }
    
    print(selected_month)
    
    result <- nycflights13::flights %>% 
      filter(month == selected_month) %>% 
      group_by(carrier) %>% 
      count()

    
    plot <- result %>% 
      ggplot(aes(x = carrier, y = n)) + 
      geom_bar(stat="identity") + 
      labs(x="Airline",y="Flight Count")
    
    plot %>% 
      ggplotly()
    
  })
  
  observeEvent(input$month, {
    js$resetClick()
  })

 
}

# Run the application 
shinyApp(ui = ui, server = server)


With the updated RStudio version I have yet to crash. :+1:

It works fine in the preview version! Thanks for your help! :slight_smile: