• R/O
  • SSH

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

Commit MetaInfo

修订版4724028705d4b5d4533fcc3644fff3c19e384ed0 (tree)
时间2022-09-19 18:08:35
作者Lorenzo Isella <lorenzo.isella@gmai...>
CommiterLorenzo Isella

Log Message

A code to generate an automatic report from Shiny.

更改概述

差异

diff -r 340ce0139fe3 -r 4724028705d4 R-codes/shiny_generate_report.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/R-codes/shiny_generate_report.R Mon Sep 19 11:08:35 2022 +0200
@@ -0,0 +1,37 @@
1+library(shiny)
2+
3+ ui = fluidPage(
4+ sliderInput("slider", "Slider", 1, 100, 50),
5+ downloadButton("report", "Generate report")
6+ )
7+
8+
9+ server = function(input, output) {
10+ output$report <- downloadHandler(
11+ # For PDF output, change this to "report.pdf"
12+ filename = "report.docx",
13+ content = function(file) {
14+ # Copy the report file to a temporary directory before processing it, in
15+ # case we don't have write permissions to the current working dir (which
16+ # can happen when deployed).
17+ tempReport <- file.path(tempdir(), "report_generator.Rmd")
18+ file.copy("report_generator.Rmd", tempReport, overwrite = TRUE)
19+
20+ # Set up parameters to pass to Rmd document
21+ params <- list(n = input$slider)
22+
23+ # Knit the document, passing in the `params` list, and eval it in a
24+ # child of the global environment (this isolates the code in the document
25+ # from the code in this app).
26+ rmarkdown::render(tempReport, output_file = file,
27+ params = params,
28+ envir = new.env(parent = globalenv())
29+ )
30+ }
31+ )
32+ }
33+
34+
35+
36+shinyApp(ui = ui, server = server)
37+