R/save_gt_module.R

Defines functions save_gt_server save_gt_ui

# ui --------------------------------------------------------------------------
save_gt_ui <- function(id) {
  ns <- NS(id)

  dropdownButton(
    inputId = ns('drop_btn'),
    label = 'Save',
    tagList(
      h3('Save table'),
      textInput(ns('file_name'), 'File name', value = 'table'),
      radioGroupButtons(ns('radio_format'), 'Format',
                        c('html', 'rtf'), size = 'sm', individual = T),
      downloadButton(ns('down_handler'), 'Save table', icon('download')),
      br()),
    circle = F, size = 'sm', icon = icon('download')
  )
}

# server ----------------------------------------------------------------------
save_gt_server <- function(id, input_table) {
  moduleServer(id, function(input, output, session) {

    output$down_handler <- downloadHandler(

      filename = function() {
        req(input_table())
        paste0(input$file_name, switch(input$radio_format, html = '.html', rtf = '.rtf'))
      },
      content = function(file) {
        req(input_table())
        gtsave(input_table(), file)
      }
    )
  })
}

Try the spada package in your browser

Any scripts or data that you put into this service are public.

spada documentation built on July 10, 2026, 9:07 a.m.