简体   繁体   English

生成自定义的 Rmarkdown 文档

[英]Generate a customized Rmarkdown document

I have a shiny application in which a user can enter information through a form with various inputs like text, date etc. Once entered, this information is stored in a table in the backend.我有一个 shiny 应用程序,用户可以在其中通过具有各种输入(如文本、日期等)的表单输入信息。输入后,此信息将存储在后端的表格中。 Now on the basis of this, the user wants to generate a document/pdf in a particular format for printing.现在在此基础上,用户希望生成特定格式的文档/pdf 用于打印。 Here is a demo of what the final filled up form might look like:这是最终填写表格的演示:

在此处输入图像描述

All the fields, for example, the billed to address, payment method, shipped to etc. are entered through the form and are stored in a table.所有字段,例如开票地址、付款方式、运送到等,都通过表格输入并存储在表格中。 How do I extract this information from a table and show it in this format?如何从表格中提取此信息并以这种格式显示? I am looking at parameterized Rmarkdown documents, but don't know how to get the format correct.我正在查看参数化的 Rmarkdown 文档,但不知道如何正确获取格式。

As for getting parameters into an rmarkdown file, you can use the yaml header.至于将参数放入 rmarkdown 文件,您可以使用 yaml header。 Since your data is most likely coming from a reactive environment, you have to save the object to the global environment using the <<- operator or assign() .由于您的数据很可能来自反应式环境,因此您必须使用<<-运算符或assign()将 object 保存到全局环境中。 These values can then be accessed from the Rmarkdown file with the yaml header.然后可以使用 yaml header 从 Rmarkdown 文件访问这些值。 Say you have created an object called address :假设您创建了一个名为address的 object :

---
output: pdf_document
address: NA
---

As of the formatting the report, you will need to use latex code, either inside the Rmarkdown document and/or you specify a .tex file in the yaml header:在格式化报告时,您需要在 Rmarkdown 文档中使用latex代码和/或在 yaml Z099FB995346F31C749F6E40DB0F395EZ 中指定.tex文件:

---
output:
  pdf_document:
    includes:
      in_header: preamble.tex
address: NA
---

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM