A short function to render the rmarkdown report on Shiny.
Examples
# Minimal example that renders a temporary Rmd file.
# Safe for CRAN because it only writes to tempdir() and runs
# conditionally if rmarkdown is installed.
# \donttest{
if (requireNamespace("rmarkdown", quietly = TRUE)) {
# Create a temporary Rmd that declares params in the YAML
rmd_file <- tempfile(fileext = ".Rmd")
writeLines(c(
"---",
"title: \"Test Report\"",
"output: html_document",
"params:",
" value: 0",
"---",
"",
"This is a test report.",
"",
"Parameter value: `r params$value`"
), con = rmd_file)
# Output location
out_file <- tempfile(fileext = ".html")
# Example parameters to pass in
example_params <- list(value = 123)
# Render report
renderReport(
input = rmd_file,
output = out_file,
params = example_params
)
# Optionally inspect the output path
out_file
}
#>
#>
#> processing file: file1ead5d091dc0.Rmd
#> 1/1
#> output file: file1ead5d091dc0.knit.md
#> /opt/hostedtoolcache/pandoc/3.1.11/x64/pandoc +RTS -K512m -RTS file1ead5d091dc0.knit.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output /tmp/RtmpLzzMlQ/file1ead4240bb43.html --lua-filter /home/runner/work/_temp/Library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /home/runner/work/_temp/Library/rmarkdown/rmarkdown/lua/latex-div.lua --embed-resources --standalone --variable bs3=TRUE --section-divs --template /home/runner/work/_temp/Library/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --variable theme=bootstrap --mathjax --variable 'mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' --include-in-header /tmp/RtmpLzzMlQ/rmarkdown-str1ead4d38ba9a.html
#>
#> Output created: /tmp/RtmpLzzMlQ/file1ead4240bb43.html
#> [1] "/tmp/RtmpLzzMlQ/file1ead4240bb43.html"
# }
