Saving {{gt}} tables in shiny

Hi,

I'm having trouble saving a {{gt}} table with {{shinyscreenshot}}. Numeric columns have a cropped resolution.

Is this a gt or shinyscreenshot problem and how can I fix this?

Are there other solutions to saving gt output from shiny, possibly by working with downloadHandler and gt_save? (r - How to save plots that are made in a shiny app - Stack Overflow)

Thanks!

library(shiny)
library(gt)
library(magrittr)
library(shinyscreenshot)


gt_tbl <-
    gtcars %>%
    gt() %>%
    cols_hide(contains("_"))

ui <- fluidPage(

    gt_output(outputId = "table"),
    actionButton("screenshot", "Screenshot gt"),
)

server <- function(input,
                   output,
                   session) {

    output$table <-
        render_gt(
            expr = gt_tbl,
            height = px(600),
            width = px(600)
        )

    observeEvent(input$screenshot, {
        shinyscreenshot::screenshot(id = "table")
    })
}

if (interactive()) {
    shinyApp(ui, server)
}

this worked: saves the gt as temp file and uses file.copy to download

    library(shiny)
    library(gt)
    library(dplyr)
     
     
     
    ui <- fluidPage(
      downloadButton("report", "Generate Report")
    )
     
     
     
    server <- function(input, output, session) {
      my_table <- reactive({
        mtcars[1:5, 1:5] %>%
          gt()  
      })
      
      my_image <- reactive({
        
        outfile <- tempfile(fileext = ".png")
        
        gtsave(data = my_table(), 
               filename = outfile, 
               vwidth = 400, 
               vheight = 300)
        
        outfile
        
      })
      
      output$report <- downloadHandler(
        filename = "download.png",
        
        content = function(file) {
          file.copy(my_image(), file)
          
        },
        contentType = 'image/png'
      )
    }
     
    shinyApp(ui, server)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.