Created
November 21, 2022 00:08
-
-
Save MayaGans/522981ffb125182d4422008f04a2f017 to your computer and use it in GitHub Desktop.
print tables to report
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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