【问题标题】:How to add table of contents in rmarkdown html Shiny app如何在 rmarkdown html Shiny 应用程序中添加目录
【发布时间】:2017-06-09 00:01:16
【问题描述】:

基于此link,我尝试在 HTML rmarkdown 输出中包含目录。如果我只是在 RStudio 中 knit 它,这可以正常工作,但是当我在 Shiny 中尝试相同时,目录不会显示。我做错了什么还是这根本不可能?我也尝试了一些自定义 css,但这似乎也不起作用。我需要这个,因为我的用户需要设置一些输入并自己使用 toc 下载交互式文档。请在下面找到一个示例。

服务器.r

library(shiny)
library(rmarkdown)
library(htmltools)
library(knitr)
shinyServer(function(input, output) {

  output$distPlot <- renderPlot({

    # generate bins based on input$bins from ui.R
    x    <- faithful[, 2]
    bins <- seq(min(x), max(x), length.out = input$bins + 1)

    # draw the histogram with the specified number of bins
    hist(x, breaks = bins, col = 'darkgray', border = 'white')

  })
  output$Generate_PDF_Document <- downloadHandler(

    # For PDF output, change this to "report.pdf"
    filename = paste0("Highchart Document",format(Sys.Date(),"%d%m%Y"),".html"),
    content = function(file) {
      #   # Copy the report file to a temporary directory before processing it, in
      #   # case we don't have write permissions to the current working dir (which
      #   # can happen when deployed).
      tempReport <- normalizePath('Test.Rmd')
      file.copy(tempReport, "Test.Rmd", overwrite = FALSE)


      # Knit the document, passing in the `params` list, and eval it in a
      # child of the global environment (this isolates the code in the document
      # from the code in this app).
      out <- render('Test.Rmd', html_document())
      file.rename(out,file)
    })

})

ui.r

library(shiny)

shinyUI(fluidPage(

  # Application title
  titlePanel("Old Faithful Geyser Data"),

  # Sidebar with a slider input for number of bins
  sidebarLayout(
    sidebarPanel(
      sliderInput("bins",
                  "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)
    ),

    # Show a plot of the generated distribution
    mainPanel(
      plotOutput("distPlot"),
      downloadButton('Generate_PDF_Document','Generate a PDF Report')
    )
  )
))

rmarkdown 文档:

---
title: "Test"
output:
  html_document:
    toc: true
    toc_depth: 3
    toc_float: true
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

【问题讨论】:

    标签: html css r shiny r-markdown


    【解决方案1】:

    render 中删除html_document()。我没有研究细节,但它看起来像是强制覆盖 yaml 前端问题。

    【讨论】:

      猜你喜欢
      • 2014-07-20
      • 2017-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-19
      • 2016-05-28
      • 1970-01-01
      相关资源
      最近更新 更多