gpt4 book ai didi

html - 如何在 rmarkdown html Shiny app 中添加目录

转载 作者:行者123 更新时间:2023-11-28 15:51:34 25 4
gpt4 key购买 nike

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

服务器.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)
})

})

用户界面

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.

最佳答案

render 中移除 html_document()。我没有研究细节,但看起来它强制覆盖了 yaml 前面的内容。

关于html - 如何在 rmarkdown html Shiny app 中添加目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41823935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com