I am trying to create a parameterised Rmarkdown document with custom template that can be edited via a shiny app. When I run the document in Rstudio via the
knit button, it works fine. When I run the document from console with
rmarkdown::render() the parameters aren't passed through, and the defaults defined in the document are used.
Here is a minimal Rmarkdown document:
--- title: Test report output: html_document: template: report_template.html params: text: "Foo" --- Hello world!
report_template.html defined as:
<!DOCTYPE html> <head> <title>$title$</title> </head> <body> <h1>$title$</h1> You entered $params.text$ $body$ </body> </html>
When knitting via the
knit button all works as it should and produces the result below as expected.
However when using
rmarkdown::render("report.Rmd", output_file = "report.html", params = list(text = "Bar")) on the console, it produces the same result, and the parameter passed is ignored. I.e. I expect it to show
You entered Bar
But it still says "Foo".
What am I doing wrong? Why are the parameters not being passed into the document?
Running Windows 10, R 4.0.0, rmarkdown 2.1. Also tested on R 3.6.3 which made no difference.