| 1 |
library(shiny) |
| 2 |
library(ggplot2) |
| 3 |
library(thematic) |
| 4 |
|
| 5 |
# The device we're testing |
| 6 |
ext <- "png" |
| 7 |
|
| 8 |
ui <- fluidPage( |
| 9 |
imageOutput("ggplot"), |
| 10 |
imageOutput("lattice"), |
| 11 |
imageOutput("base") |
| 12 |
) |
| 13 |
|
| 14 |
render_image <- function(expr) { |
| 15 |
snapshotPreprocessOutput(renderImage(expr, deleteFile = FALSE), function(value) {}) |
| 16 |
} |
| 17 |
|
| 18 |
image_info <- function(type, ext) { |
| 19 |
list( |
| 20 |
src = paste0(type, "-1.", ext), |
| 21 |
width = 600, height = 400 |
| 22 |
) |
| 23 |
} |
| 24 |
|
| 25 |
# Knit all the Rmds |
| 26 |
# Note that this is done inside the server function |
| 27 |
# to avoid a timeout issue with shinytest::testApp() |
| 28 |
infile <- "darkly.Rmd" |
| 29 |
rmd_txt <- knitr::knit_expand("../../template_theme.Rmd", theme = "darkly") |
| 30 |
writeLines(rmd_txt, infile) |
| 31 |
outfile <- rmarkdown::render(infile) |
| 32 |
|
| 33 |
onStop(function() { |
| 34 |
unlink(infile) |
| 35 |
unlink(dir(pattern = paste0("\\.", ext))) |
| 36 |
unlink( |
| 37 |
c(infile, outfile, paste0(tools::file_path_sans_ext(infile), "_files")), |
| 38 |
recursive = TRUE |
| 39 |
) |
| 40 |
}) |
| 41 |
|
| 42 |
server <- function(input, output, session) { |
| 43 |
|
| 44 |
output$ggplot <- render_image(image_info("ggplot", ext)) |
| 45 |
output$lattice <- render_image(image_info("lattice", ext)) |
| 46 |
output$base <- render_image(image_info("base", ext)) |
| 47 |
} |
| 48 |
|
| 49 |
shinyApp(ui, server) |