R Plotly scatter plot with size assigned to a variable crashes browser with > ~10000 points

Hello, I’m having an issue with R plotly scatterplots crashing my chrome or edge browser. It appears to load OK if you only have about 10000 points or less. My data set usually is between 15K-50K and it’s meant for the user to see general trends of the data but then filter it down, but visualizing all those points is important. Below is a reproducible example, you can adjust the number of points generated in the dataset between 50K and 10K to see the performance difference along with turning marker = list(size = ~size_var_num), on and off to see without that it will load in chrome. As an FYI everything runs ok in the RStudio app preview window, but once you go to chrome it won’t load and usually crashes the browser completely and I have to use task manager to close it out.

Is this expected for data sets of this size or is there a solution where the size works at 50K records and won’t crash chrome? I see the same issue when the app is deployed to an RStudio Connect server. Also posted on RStudio Community here.

See code below, appreciate any thoughts!

library(shiny)
library(plotly)
library(tidyverse)

data_set <- tibble(xvar = runif(50000), yvar = runif(50000), sizevar = runif(50000)) %>% 
#data_set <- tibble(xvar = runif(10000), yvar = runif(10000), sizevar = runif(10000)) %>% 
  mutate(size_var_num = case_when(
           sizevar < .2 ~ 5,
           sizevar < .4 ~ 10,
           sizevar < .6 ~ 15,
           sizevar < .8 ~ 20,
           TRUE ~ 25
         ))

ui <- fluidPage(
  headerPanel('Example'),
  sidebarPanel(shinyWidgets::noUiSliderInput(
                 inputId = "xvar_slider",
                 label = "xvar slider : ",
                 behaviour = "drag",
                 min = 0,
                 max = 1,
                 value = c(0,100),
                 step = .001,
                 color = "#3c8dbc"
               )),
  mainPanel(
    plotlyOutput('plot')
  )
)

server <- function(input, output) {
  
  data <- reactive({
    
    data_set %>% 
      filter(xvar >= input$xvar_slider[1] & xvar <= input$xvar_slider[2]) %>% 
      mutate(label = paste0("xvar: ", xvar, "\nyvar: ", yvar, "\nxvar percent: ", round(xvar,2)*100, 
                            "%\nyvar dollar: $", format(yvar*100000, big.mark=",")))

  })
  
  output$plot <- renderPlotly(
    
    data() %>% 
      plot_ly(
      x = ~xvar,
      y = ~yvar, 
      marker = list(size = ~size_var_num), #, sizemode = 'diameter', sizeref = 2.5
      opacity = 1,
      type = 'scatter',
      mode = 'markers',
      hoverinfo = 'text',
      hovertext = ~label)
  )
  
}

shinyApp(ui,server)

Solution was simply to add toWebGL() at the end. I was already on plotly 4.10.0. Resolved in my RStudio Comm post here.