plotly.R icon indicating copy to clipboard operation
plotly.R copied to clipboard

ggplotly crashes when AGG is required as graphical engine

Open tvedebrink opened this issue 10 months ago • 2 comments

I'm developing Shiny apps in a platform, where the graphical engine in RStudio (browser version) needs to be AGG. When making interactive plots with ggplotly the app crashes when running from RStudio with the following error message:

Listening on http://127.0.0.1:7615
Warning: Error in dev_fun: X11 is not available
  106: dev_fun
  105: gg2list
  104: ggplotly.ggplot
  103: ggplotly
  102: %>%
  101: renderPlotly [/PATH_TO_APP/app.R#77]
  100: func
   97: shinyRenderWidget
   96: func
   83: renderFunc
   82: output$distggPlotly
    1: runApp

The static plots in the app are working fine, but the plotly variant causes the problem (see below).

app.R file

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

ui <- fluidPage(

    titlePanel("Old Faithful Geyser Data"),

    sidebarLayout(
        sidebarPanel(
            sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30)
        ),

        mainPanel(
           plotOutput("distPlot"),
           plotOutput("distggPlot"),
           plotlyOutput("distggPlotly")
        )
    )
)

server <- function(input, output) {
  output$distPlot <- renderPlot({
      x    <- faithful[, 2]
      bins <- seq(min(x), max(x), length.out = input$bins + 1)

      hist(x, breaks = bins, col = 'darkgray', border = 'white',
           xlab = 'Waiting time to next eruption (in mins)',
           main = 'Histogram of waiting times')
  })
    
  output$distggPlot <- renderPlot({
    x    <- faithful[, 2]
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    
    faithful %>% ggplot(aes(x = waiting)) +
      geom_histogram(breaks = bins, fill = 'darkgray', colour = 'white') + 
      labs(x = 'Waiting time to next eruption (in mins)',
           title = 'Histogram of waiting times')
  })
    
  output$distggPlotly <- renderPlotly({
    x    <- faithful[, 2]
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    
    gg_hist <- faithful %>% ggplot(aes(x = waiting)) +
      geom_histogram(breaks = bins, fill = 'darkgray', colour = 'white') + 
      labs(x = 'Waiting time to next eruption (in mins)',
           title = 'Histogram of waiting times')
    gg_hist %>% ggplotly()
  })
    
}

shinyApp(ui = ui, server = server)

tvedebrink avatar Aug 10 '23 07:08 tvedebrink

Huh, I can't seem to replicate this, would you mind sharing your sessioninfo::session_info()? I have a hunch that upgrading the Rstudio IDE might fix the issue?

cpsievert avatar Aug 10 '23 13:08 cpsievert

Thanks the for swift reply, @cpsievert. I think that the hint of updating the RStudio version is a very good first step (I've asked my sys admins to try this).

While waiting for this, I have posted the output you requested below

> session_info()
─ Session info ──────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.2.3 (2023-03-15)
 os       AlmaLinux 8.7 (Stone Smilodon)
 system   x86_64, linux-gnu
 ui       RStudio
 language (EN)
 collate  C.UTF-8
 ctype    C.UTF-8
 tz       UTC
 date     2023-08-11
 rstudio  2022.07.2+576 Spotted Wakerobin (server)
 pandoc   2.18 @ /usr/lib/rstudio-server/bin/pandoc/ (via rmarkdown)

─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version date (UTC) lib source
 bslib         0.4.2   2022-12-16 [5] CRAN (R 4.2.3)
 cachem        1.0.7   2023-02-24 [5] CRAN (R 4.2.3)
 cli           3.6.1   2023-03-23 [5] CRAN (R 4.2.3)
 colorspace    2.1-0   2023-01-23 [5] CRAN (R 4.2.3)
 crayon        1.5.2   2022-09-29 [5] CRAN (R 4.2.3)
 data.table    1.14.8  2023-02-17 [1] CRAN (R 4.2.3)
 digest        0.6.31  2022-12-11 [5] CRAN (R 4.2.3)
 dplyr       * 1.1.2   2023-04-20 [3] CRAN (R 4.2.3)
 ellipsis      0.3.2   2021-04-29 [5] CRAN (R 4.2.3)
 evaluate      0.20    2023-01-17 [5] CRAN (R 4.2.3)
 fansi         1.0.4   2023-01-22 [5] CRAN (R 4.2.3)
 farver        2.1.1   2022-07-06 [5] CRAN (R 4.2.3)
 fastmap       1.1.1   2023-02-24 [5] CRAN (R 4.2.3)
 forcats     * 1.0.0   2023-01-29 [1] CRAN (R 4.2.3)
 generics      0.1.3   2022-07-05 [5] CRAN (R 4.2.3)
 ggplot2     * 3.4.2   2023-04-03 [5] CRAN (R 4.2.3)
 glue          1.6.2   2022-02-24 [5] CRAN (R 4.2.3)
 gtable        0.3.3   2023-03-21 [5] CRAN (R 4.2.3)
 hms           1.1.3   2023-03-21 [1] CRAN (R 4.2.3)
 htmltools     0.5.5   2023-03-23 [5] CRAN (R 4.2.3)
 htmlwidgets   1.6.2   2023-03-17 [5] CRAN (R 4.2.3)
 httpuv        1.6.9   2023-02-14 [5] CRAN (R 4.2.3)
 httr          1.4.5   2023-02-24 [5] CRAN (R 4.2.3)
 jquerylib     0.1.4   2021-04-26 [5] CRAN (R 4.2.3)
 jsonlite      1.8.4   2022-12-06 [5] CRAN (R 4.2.3)
 knitr         1.42    2023-01-25 [5] CRAN (R 4.2.3)
 labeling      0.4.2   2020-10-20 [5] CRAN (R 4.2.3)
 later         1.3.0   2021-08-18 [5] CRAN (R 4.2.3)
 lazyeval      0.2.2   2019-03-15 [1] CRAN (R 4.2.3)
 lifecycle     1.0.3   2022-10-07 [5] CRAN (R 4.2.3)
 lubridate   * 1.9.2   2023-02-10 [1] CRAN (R 4.2.3)
 magrittr      2.0.3   2022-03-30 [5] CRAN (R 4.2.3)
 memoise       2.0.1   2021-11-26 [5] CRAN (R 4.2.3)
 mime          0.12    2021-09-28 [5] CRAN (R 4.2.3)
 munsell       0.5.0   2018-06-12 [5] CRAN (R 4.2.3)
 pillar        1.9.0   2023-03-22 [5] CRAN (R 4.2.3)
 pkgconfig     2.0.3   2019-09-22 [5] CRAN (R 4.2.3)
 plotly      * 4.10.1  2022-11-07 [1] CRAN (R 4.2.3)
 promises      1.2.0.1 2021-02-11 [5] CRAN (R 4.2.3)
 purrr       * 1.0.1   2023-01-10 [5] CRAN (R 4.2.3)
 R6            2.5.1   2021-08-19 [5] CRAN (R 4.2.3)
 ragg          1.2.5   2023-01-12 [1] CRAN (R 4.2.3)
 Rcpp          1.0.10  2023-01-22 [5] CRAN (R 4.2.3)
 readr       * 2.1.4   2023-02-10 [1] CRAN (R 4.2.3)
 rlang         1.1.0   2023-03-14 [5] CRAN (R 4.2.3)
 rmarkdown     2.21    2023-03-26 [5] CRAN (R 4.2.3)
 rstudioapi    0.14    2022-08-22 [5] CRAN (R 4.2.3)
 sass          0.4.5   2023-01-24 [5] CRAN (R 4.2.3)
 scales        1.2.1   2022-08-20 [5] CRAN (R 4.2.3)
 sessioninfo * 1.2.2   2021-12-06 [7] CRAN (R 4.2.3)
 shiny       * 1.7.4   2022-12-15 [5] CRAN (R 4.2.3)
 stringi       1.7.12  2023-01-11 [5] CRAN (R 4.2.3)
 stringr     * 1.5.0   2022-12-02 [5] CRAN (R 4.2.3)
 systemfonts   1.0.4   2022-02-11 [1] CRAN (R 4.2.3)
 textshaping   0.3.6   2021-10-13 [1] CRAN (R 4.2.3)
 tibble      * 3.2.1   2023-03-20 [5] CRAN (R 4.2.3)
 tidyr       * 1.3.0   2023-01-24 [5] CRAN (R 4.2.3)
 tidyselect    1.2.0   2022-10-10 [5] CRAN (R 4.2.3)
 tidyverse   * 2.0.0   2023-02-22 [1] CRAN (R 4.2.3)
 timechange    0.2.0   2023-01-11 [1] CRAN (R 4.2.3)
 tzdb          0.3.0   2022-03-28 [1] CRAN (R 4.2.3)
 utf8          1.2.3   2023-01-31 [5] CRAN (R 4.2.3)
 vctrs         0.6.1   2023-03-22 [5] CRAN (R 4.2.3)
 viridisLite   0.4.1   2022-08-22 [5] CRAN (R 4.2.3)
 withr         2.5.0   2022-03-03 [5] CRAN (R 4.2.3)
 xfun          0.38    2023-03-24 [5] CRAN (R 4.2.3)
 xtable        1.8-4   2019-04-21 [5] CRAN (R 4.2.3)
 yaml          2.3.7   2023-01-23 [5] CRAN (R 4.2.3)

 [1] /opt/dataiku/R/R.lib/4.x

tvedebrink avatar Aug 11 '23 10:08 tvedebrink