| 1 |
library(shiny) |
| 2 |
library(ggplot2) |
| 3 |
library(thematic) |
| 4 |
|
| 5 |
# The device we're testing |
| 6 |
device <- "quartz_png" |
| 7 |
ext <- "png" |
| 8 |
|
| 9 |
ui <- fluidPage( |
| 10 |
imageOutput("ggplot"), |
| 11 |
imageOutput("lattice"), |
| 12 |
imageOutput("base") |
| 13 |
) |
| 14 |
|
| 15 |
render_image <- function(expr) { |
| 16 |
snapshotPreprocessOutput(renderImage(expr, deleteFile = FALSE), function(value) {}) |
| 17 |
} |
| 18 |
|
| 19 |
image_info <- function(type, ext) { |
| 20 |
list( |
| 21 |
src = paste0(type, "-1.", ext), |
| 22 |
width = 600, height = 400 |
| 23 |
) |
| 24 |
} |
| 25 |
|
| 26 |
server <- function(input, output, session) { |
| 27 |
# Knit all the Rmds |
| 28 |
# Note that this is done inside the server function |
| 29 |
# to avoid a timeout issue with shinytest::testApp() |
| 30 |
rmd_txt <- knitr::knit_expand("../template_device.Rmd", device = sprintf("'%s'", device)) |
| 31 |
res <- callr::r(function(...) { knitr::knit2html(...) }, args = list(text = rmd_txt)) |
| 32 |
|
| 33 |
output$ggplot <- render_image(image_info("ggplot", ext)) |
| 34 |
output$lattice <- render_image(image_info("lattice", ext)) |
| 35 |
output$base <- render_image(image_info("base", ext)) |
| 36 |
|
| 37 |
onFlush(function() { |
| 38 |
unlink(dir(pattern = paste0("\\.", ext))) |
| 39 |
}) |
| 40 |
} |
| 41 |
|
| 42 |
shinyApp(ui, server) |