Skip to content

Instantly share code, notes, and snippets.

@MayaGans
Created November 21, 2022 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MayaGans/522981ffb125182d4422008f04a2f017 to your computer and use it in GitHub Desktop.
Save MayaGans/522981ffb125182d4422008f04a2f017 to your computer and use it in GitHub Desktop.
print tables to report
library(shiny)
ui <- fluidPage(
uiOutput("all_the_tables"),
downloadButton("download", "DOWNLOAD_ALL")
)
# Define server logic required to draw a histogram
server <- function(input, output) {
data <- reactive({
list(
DF1 = data.frame(
a = 1,
b = 2
),
DF2 = data.frame(
c = 3,
d = 4
)
)
})
# output$all_the_tables <- renderUI({
# purrr::map(data(), DT::datatable)
# })
output$download <- downloadHandler(
filename = "report.pdf",
content = function(file) {
tempReport <- file.path(tempdir(), "report.Rmd")
file.copy("report.Rmd", tempReport, overwrite = TRUE)
params <- list(data = data())
rmarkdown::render(tempReport, output_file = file,
params = params,
envir = new.env(parent = globalenv())
)
}
)
}
# Run the application
shinyApp(ui = ui, server = server)
---
title: "All Tables"
date: "`r Sys.Date()`"
output:
pdf_document:
number_sections: true
keep_tex: yes
header-includes:
\usepackage{caption}
\usepackage{helvet}
\renewcommand\familydefault{\sfdefault}
include-before:
- '`\newpage{}`{=latex}'
classoption: landscape
params:
data: NA
---
\captionsetup[table]{labelformat=empty}
```{r, echo=FALSE, results='asis'}
for(i in 1:length(params$data)){
current_object <- params$data[[i]]
print(
knitr::kable(
current_object,
caption = names(params$data)[i],
),
type = "latex"
)
cat("\n\n\\pagebreak\n")
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment