library(shiny)
library(capture)
<- fluidPage(
ui $h2("Capture example"),
tagscapture(
selector = "body",
filename = "all-page",
icon("camera"), "Take screenshot of all page",
format = "jpeg"
),$br(),
tagsfluidRow(
column(
width = 4,
wellPanel(
$b("Parameters :"),
tags
selectInput(
inputId = "loi",
label = "Law:",
choices = c("normal", "uniform", "exponential")
)
)
),column(
width = 8,
$div(
tagsid = "result-block",
$b("Results :"),
tagsplotOutput(outputId = "plot"),
uiOutput(outputId = "mean"),
verbatimTextOutput(outputId = "raw")
),capture(
selector = "#result-block",
filename = "results-screenshot",
icon("camera"), "Take screenshot of results",
options = list(backgroundColor = "#FFF")
),capture(
selector = "#result-block",
filename = "results-screenshot",
icon("camera"), "Take screenshot of results (bigger scale)",
scale = 3,
options = list(backgroundColor = "#FFF")
),capture(
selector = "#result-block",
filename = NULL, # no download client side
icon("camera"), "Take screenshot of results (retrieve server side)",
inputId = "screenshot",
options = list(backgroundColor = "#FFF")
),uiOutput("out")
)
)
)
<- function(input, output, session) {
server
$out <- renderUI({
output# # Here we display image back in interface,
# # but you can also write image on disk
# write_png <- function(x, filename) {
# x <- sub(".*,", "", x)
# x <- base64enc::base64decode(x)
# png::writePNG(png::readPNG(x), filename)
# }
# write_png(input$screenshot, "myimage.png")
$img(src = input$screenshot)
tags
})
<- reactive({
distrib_r switch(
$loi,
input"normal" = rnorm(1000),
"uniform" = runif(1000),
"exponential" = rexp(1000)
)
})
$plot <- renderPlot({
outputhist(distrib_r())
})
$mean <- renderUI({
output$p(tags$b("The mean is :"), round(mean(distrib_r()), 2))
tags
})
$raw <- renderPrint({
outputsummary(distrib_r())
})
}shinyApp(ui, server)
Shiny应用如何增加截图功能
R语言
Shiny开发
使用capture包为Shiny应用截图