Koffi Frederic Sessie
Koffi Frederic Sessie

Reputation: 71

Issue with gtsave() and Chrome on shinyapps.io

I've been encountering an issue with the gtsave() function from the gt package when trying to save a table as a PNG file. The error message indicates that it cannot find an available port to start Chrome.

Locally, gtsave() works perfectly in my Shiny app. However, after deploying the app to shinyapps.io, the error occurs, and the download is blocked by Chrome. I’ve searched online but haven’t been able to find a solution.

I’m using chromote version 0.3.1.

Does anyone know how I can fix this?

Below is my session info and the minimal example

devtools::session_info("chromote")
─ Session info ──────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.2.2 (2022-10-31 ucrt)
 os       Windows 10 x64 (build 22631)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  French_France.utf8
 ctype    French_France.utf8
 tz       Europe/Paris
 date     2024-11-29
 rstudio  2024.09.1+394 Cranberry Hibiscus (desktop)
 pandoc   3.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)

─ Packages ──────────────────────────────────────────────────────────────────────
 ! package     * version  date (UTC) lib source
   AsioHeaders   1.22.1-2 2022-12-08 [1] RSPM
 P chromote    * 0.3.1    2024-08-30 [?] RSPM
   cpp11         0.5.0    2024-08-27 [1] RSPM
 P curl          6.0.1    2024-11-14 [?] RSPM
 P fastmap       1.2.0    2024-05-15 [?] RSPM
 P jsonlite      1.8.9    2024-09-20 [?] RSPM
 P later         1.3.0    2021-08-18 [?] CRAN (R 4.2.2)
 P magrittr    * 2.0.3    2022-03-30 [?] CRAN (R 4.2.2)
 P processx      3.8.4    2024-03-16 [?] RSPM
 P promises      1.2.0.1  2021-02-11 [?] CRAN (R 4.2.2)
 P ps            1.8.1    2024-10-28 [?] RSPM
 P R6            2.5.1    2021-08-19 [?] CRAN (R 4.2.2)
 P Rcpp          1.0.13   2024-07-17 [?] RSPM
 P rlang         1.1.4    2024-06-04 [?] RSPM
 P websocket     1.4.2    2024-07-22 [?] RSPM

 P ── Loaded and on-disk path mismatch.````


## Minimal example

library(shiny)
library(gt)
library(webshot2)

# Sample data creation
df <- data.frame(
  Product = c("Product A", "Product B", "Product C"),
  Price = c(100, 200, 300),
  Quantity = c(5, 3, 8),
  Total = c(500, 600, 2400)
)

ui <- page_fluid(
  title = "GT Screenshot",
  
  card(
    card_header("Table and Capture Button"),
    
    gt_output("table"),
    
    downloadButton("capture", "Capture and Download", 
                   class = "btn-primary mt-3")
  )
)

server <- function(input, output, session) {
  
  # GT table creation and display
  output$table <- render_gt({
    gt(df) %>%
      tab_header(
        title = "My Table"
      ) %>%
      fmt_number(
        columns = c(Price, Total),
        decimals = 2
      ) %>%
      tab_style(
        style = cell_text(weight = "bold"),
        locations = cells_column_labels()
      )
  })
  
  # Download handler
  output$capture <- downloadHandler(
    filename = function() {
      paste0("table_capture_", format(Sys.time(), "%Y%m%d_%H%M%S"), ".png")
    },
    content = function(file) {
      gt_table <- gt(df) %>%
        tab_header(
          title = "My Table"
        ) %>%
        fmt_number(
          columns = c(Price, Total),
          decimals = 2
        ) %>%
        tab_style(
          style = cell_text(weight = "bold"),
          locations = cells_column_labels()
        )
      
      gtsave(
        gt_table,
        filename = file,
        expand = 15,
        vwidth = 3000,
        vheight = 2000,
        zoom = 3
      )
    }
  )
}

shinyApp(ui = ui, server = server)

Upvotes: 0

Views: 46

Answers (0)

Related Questions