【发布时间】:2020-12-13 17:52:04
【问题描述】:
我在 Shinyapp 生成的降价中生成目录时遇到问题。 我尝试在 YAML 中设置 toc = TRUE 但它不起作用。
应用程序是这样的,一个上传一些数据的界面和一个渲染一些图形的 Markdown。
问题是生成pdf、html或word的时候没有生成目录。
app.R
library(shiny)
library(dplyr)
library(qcc)
library(ggplot2)
library(readxl)
library(kableExtra)
library(knitr)
shinyApp(ui =
fluidPage(fileInput("file", "Cargar Datos", multiple = FALSE),
radioButtons('format', 'Formato del documento', c('PDF', 'HTML', 'Word'),inline = TRUE),
downloadButton('downloadReport')),
server = function(input, output, session){
myData <- reactive({ infile <- input$file
if(is.null(infile)) return(NULL)
data <- read_excel(infile$datapath)
data})
plotData <- function(){plot(myData}
output$downloadReport <- downloadHandler(
filename = function() {
paste('my-report', sep = '.', switch(
input$format, PDF = 'pdf', HTML = 'html', Word = 'docx'
))
},
content = function(file) {
src <- normalizePath('report.Rmd')
# temporarily switch to the temp dir, in case you do not have write
# permission to the current working directory
owd <- setwd(tempdir())
on.exit(setwd(owd))
file.copy(src, 'report.Rmd', overwrite = TRUE)
library(rmarkdown)
out <- render('report.Rmd', switch(
input$format,
PDF = pdf_document(), HTML = html_document(), Word = word_document()
))
file.rename(out, file)
}
)
########################################
####
})
report.Rmd
---
title: "title"
subtitle: "subtitle"
output:
toc: true
toc_depth: 4
number_sections: true
author:
- "a1"
- "a2"
date: "`r format(Sys.Date(), '%B %d, %Y')`"
params:
p1: "p1"
p2: "p2"
---
# section1
## section1.1
# section2
```{r}
plotData()
【问题讨论】:
-
尝试将选项作为参数传递给渲染函数,例如
rmarkdown::render('report.Rmd', rmarkdown::pdf_document(toc = TRUE, toc_depth = 4, number_sections = TRUE))
标签: r shiny r-markdown