首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >shinyapp渲染中的目录

shinyapp渲染中的目录
EN

Stack Overflow用户
提问于 2020-08-25 04:29:36
回答 1查看 281关注 0票数 0

在我的shinyapp生成的标记中,生成目录有问题。我试图在YAML中设置toc = TRUE,但它不起作用。

这个应用程序是这样的,一个上传一些数据的界面,以及一些图形呈现的标记。

问题是在生成pdf、html或word时,不生成目录。

app.R

代码语言:javascript
复制
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

代码语言:javascript
复制
---
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()

代码语言:javascript
复制
```javascript
代码语言:javascript
复制
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-15 21:18:09

尝试将这些选项作为参数传递给呈现函数。

rmarkdown::report.rmd,rmarkdown::pdf_document(toc = TRUE,toc_depth = 4,number_sections = TRUE))

stefana comment中回答了这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63572062

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档