title: R Markdown - Create Dynamic Report Parameters
body: <p>I was wondering if anyone had any thoughts on how to create dynamic parameters in a R Markdown Report.   Currently I have a report with eight parameters that are all hard coded.  I would like the values of these parameters to be dynamically derived (based off a query and therefore a data frame) and would like the value in an upper level parameter to drive the selection subset of a lower level parameter.  </p>
  
  <pre><code>---
  title: My Document
  output: html_document
  params:
    system:
      label: "Select System:"
      value: A
      input: select
      choices: [A, B]
    fig_num:
      label: "Starting Figure Number:"
      value: 1
      min: 1
      max: 100
      input: numeric
    attach_let:
      label: "Attachment Letter:"
      value: "A"
      input: text
    Program:
      label: "Select Program:"
      value: 1A 
      input: select
      choices: [1A, 1B, 2A, 2B]
    ProgramRisk:
      label: "Select Sample Program Risk:"
      value: 1
      input: select
      choices: [1, 2, 3]
  ---
  ```{r setup, include=FALSE}
  # set this option in the first code chunk in the document
  knitr::opts_chunk$set(echo = params$printcode)
  ```
  </code></pre>
  
  <p>Ideally, I would like the values for System parameter to come directly from a SQL query (e.g - SELECT DISTINCT System from A.Table).  The user would then select a value and say in the Program parameter - these values were derived from another query (e.g. SELECT DISTINCT Program FROM B.Table where System = [Param$System].   This would thereby prevent the user inputting a value in the program that did not exist for that System.    </p>
  
  <p>I have seen that you can use !r to use R code directly in the YAML header, but this seems limited to basic calls (as.Date..., etc.).   Does anyone have any ideas how I could get this information to the parameters and allow the parameters to be filtered by another (earlier) parameter? </p>
  
  <p>Any help would be appreciated!  Thank you in advance! </p>