-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.R
89 lines (56 loc) · 1.53 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
library(shiny)
# UI ----------------------------------------------------------------------
ui <- fluidPage(
selectInput(
inputId = "gender",
label = "Gender",
choices = c("Female", "Male")
),
selectInput(
inputId = "marital",
label = "Gender",
choices = c("Single", "Divorced", "Married")
),
textInput(
inputId = "filename",
label = "File name, .pdf or .html",
value = "report"
),
radioButtons(
inputId = "format",
label = "Choose output format",
choices = c("html", "pdf"),
selected = "html"
),
downloadButton(
outputId = "report",
label = "Generate report"
)
)
# server ------------------------------------------------------------------
server <- function(input, output, session) {
format <- reactive({
switch (
input$format,
"html" = "html_document",
"pdf" = "pdf_document"
)
})
output$report <- downloadHandler(
filename = input$filename,
content = function(file) {
tempReport <- file.path("temp/template.Rmd")
file.copy(from = "templated.Rmd", to = tempReport, overwrite = TRUE)
paramslist <- list(gender = input$gender, marital = input$marital)
rmarkdown::render(
input = tempReport,
output_file = input$filename,
params = paramslist,
envir = new.env(parent = globalenv()),
output_format = format(),
output_dir = getwd()
)
}
)
}
shinyApp(ui, server)