2 years ago

#64033

test-img

Piera

Bookdown - Add chapters based on user input parameters

I'm creating a bookdown report template. This report will be used by people that are not be so familiar with R, so we want them to be able to select few options on a gui (instead of working directly on the code). One of the option they would like to have is to be able to render only certain chapters, depending on the needs.

I've implemented the parameters section in the index.Rmd header, and provided the rmd_files to render depending on the 'params', but the header does not seem to accept the rmd_files option. So the only way would be to modify the _bookdown.yml. However, I tried using the parameters to modify the _bookdown.yml, but the modification does not affect the rendering because the _bookdown.yml has already been read.

Here is my index.Rmd code:

---
title: "test"
output:
  bookdown::word_document2: default
  bookdown::html_document2:
   css: "style.css"
bookdown::gitbook:
  css: "style.css"
always_allow_html: true
site: bookdown::bookdown_site
params:
  docNumber:
    label: "Doc number"
    value: 0000
    input: numeric
  finalVersion:
    label: "Final Version"
    value: false
    input: select
    choices: [true,false]
  my_files:
    label: "Files selection"
    value: "index.Rmd"
    input: select
    multiple: TRUE
    choices: ["index.Rmd","01-introduction.Rmd","02-methods.Rmd","03-results.Rmd"]
rmd_files: "`r params$my_files`"

---


finalVersionFlag <- as.logical(params$finalVersion)
docNumber <- as.numeric(params$docNumber)

knitr::opts_chunk$set(
    message = FALSE,
    warning = FALSE
)


Any idea on how to do that would be very much appreciated.

Thanks!

yaml

parameter-passing

bookdown

0 Answers

Your Answer

Accepted video resources