【问题标题】:R Markdown HTML output - Hide a section of the document while still knittingR Markdown HTML输出 - 在仍然编织的同时隐藏文档的一部分
【发布时间】:2020-04-13 04:58:55
【问题描述】:

我正在尝试从Rmarkdown 编织一个 HTML 文档,并且正在寻找一种方法来隐藏文档的一部分,同时仍然编织(执行)所有它。

我不想只隐藏代码 chunk - 这可以通过 echo = FALSE 来完成。

flexdashboards 使用{.hidden} 选项只能部分解决问题。

部分会从 HMTL 输出本身中消失,而不是 目录

代码示例:

---
output: 
  html_document: 
    df_print: kable
    fig_height: 2
    fig_width: 2
    number_sections: yes
    toc: yes
    toc_float: yes
editor_options: 
  chunk_output_type: console
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,
                      warning = FALSE, 
                      message = FALSE,
                      cache = FALSE,
                      dpi = 75,
                      comment = '')
```


# 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.

# The section I want to hide {.hidden}

Super-secret text (section content I don't want to show).

```{r}
sumCars <- summary(cars)
```


# This the section I want to show again

```{r}
sumCars[1,]
```


输出:

HTML output


如何在编织的同时隐藏文档部分?

【问题讨论】:

  • 我并不完全清楚:是要隐藏的代码块之间的文本,还是实际的代码块?或两者?您可以通过使用 include = FALSE 作为块选项来简单地隐藏代码块。它仍然会被评估。

标签: r r-markdown knitr


【解决方案1】:

导出为 html 时,您可以在 markdown 中使用任意 css。这是一个例子:


---
title: "Untitled"
output: html_document
---

# One

Hello!

# Two

<style>
 #two {
   display: none;
 }
</style>

```{r}
x <- 1:10
```

# Three

```{r}
plot(x)
```

【讨论】:

  • 一个相关问题:如何隐藏标题部分?
  • @LazarusThurston 你可以用同样的方法隐藏标题——使用CSS设置display: none;
猜你喜欢
  • 1970-01-01
  • 2021-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-18
  • 2020-02-22
  • 1970-01-01
相关资源
最近更新 更多