首页 > 解决方案 > rmarkdown yaml 中的顺序或反应参数

问题描述

我基本上有一个两层的选项组,我希望可以从中选择作为 Rmarkdown 文件中的参数。我熟悉使用参数,但想让参数 2 的选择选项取决于选择的参数 1:

如果这是一件微不足道的事情,我想象它会如何发挥作用:

示例 YAML

---
title: "Report with Reactive Parameters"
author: "Mr/Mrs. Scientist"
date: "Updated on: `r Sys.Date()`"
output: 
  html_document:
    toc: TRUE
params: 
  parent_group:
    label: "Select the Larger Collection"
    value: "collection 1"
    input: select
    choices: ["collection 1", "collection 2", "collection 3 that is much larger"]
  child_selection: 
    label: "Select a Specific Option from Parent Group:" 
    value: "child option 1"
    input: select
    choices: !r my_package::children_of_parents(parent_group = params$parent_group)
---

在这个假设的示例中,用户将首先选择更大的类别或“parent_groups”,并且基于该选择,第二个选择选项或“child_selections”将发生变化。

我包括这行my_package::children_of_parent()只是为了演示我计划如何访问选择选项。从字面上看,只是一个将字符串作为输入并返回适当的选择向量的函数。

标签: ryamlr-markdown

解决方案


推荐阅读