在 flexdashboard 中显示代码

Show code in flexdashboard

我正在尝试用 R 制作一个 flexdashboard 并想在我的演示文稿中显示代码,但这似乎不起作用。 这里有一个小例子:

---
title: "Test"
output: 
  flexdashboard::flex_dashboard
---

```{r setup, include=FALSE}
library(flexdashboard)
```

### Code

```{r, eval=FALSE, include=TRUE}
plot(iris$Sepal.Length, iris$Sepal.Width)
```   

### Output

```{r, fig.align='center', echo = FALSE}
plot(iris$Sepal.Length, iris$Sepal.Width)
```

甚至 fig.show = 'hide' 等其他卡盘选项也不起作用。 是否可以在 flexdashboard 的 R-chuck 中显示代码? 代码突出显示比纯文本更有用。

如果您希望同时显示代码和绘图,请将块选项设置为:echo = true

如果您只想将代码设置为:echo=TRUE, eval=FALSE

---
title: "Test"
output: 
  flexdashboard::flex_dashboard
---

```{r setup, include=FALSE}
library(flexdashboard)
```

### Code

```{r, echo=TRUE, eval=FALSE}
plot(iris$Sepal.Length, iris$Sepal.Width)
```   

### Code and Plot

```{r, echo=TRUE}
plot(iris$Sepal.Length, iris$Sepal.Width)
``` 

### Plot

```{r, fig.align='center', echo = FALSE}
plot(iris$Sepal.Length, iris$Sepal.Width)
```

它不会在您的演示文稿中显示为面板,但要将 </> Source Code 按钮添加到您的仪表板,请在您的 YAML 中包含 source_code: embed

--- title: "Example" output: flexdashboard::flex_dashboard: source_code: embed ---