每次單擊actionButton printNewPlot
時,我想添加一個新的報告部分,並添加新標題和新圖形圖。我怎樣才能做到這一點?閃亮 - 動態添加部分到rmarkdown報告
app.R
library(igraph)
shinyApp(
ui = fluidPage(
sliderInput("slider", "Slider", 1, 100, 50),
actionButton("printNewPlot", "Print new plot to report"),
downloadButton("report", "Download report")
),
server = function(input, output) {
output$report <- downloadHandler(
# For PDF output, change this to "report.pdf"
filename = "report.html",
content = function(file) {
# Copy the report file to a temporary directory before processing it, in
# case we don't have write permissions to the current working dir (which
# can happen when deployed).
tempReport <- file.path(tempdir(), "report.Rmd")
file.copy("report.Rmd", tempReport, overwrite = TRUE)
# Set up parameters to pass to Rmd document
params <- list(n = input$slider)
# Knit the document, passing in the `params` list, and eval it in a
# child of the global environment (this isolates the code in the document
# from the code in this app).
rmarkdown::render(tempReport, output_file = file,
params = params,
envir = new.env(parent = globalenv())
)
}
)
}
)
report.Rmd
---
title: "Dynamic report"
output: html_document
params:
n: NA
---
# I want a new title each time that printNewPlot is clicked
```{r}
plot(make_ring(params$n))
```
# If printNewPlot is clicked again, a new title must appear here
```{r}
#alongside a new plot
plot(make_ring(params$n))
```
我想擴展您的PARAMS包括來自與該命名約定的應用程序變量標題,然後使用該參數爲標題編寫一個內聯R代碼標題。 –