R Markdown Presentation 不加载/渲染交互式 Plotly 图表

R Markdown Presentation not loading/ rendering interactive Plotly chart

我正在使用 Plotly with R to create a chart that will be rendered in a R Markdown Presentation With Ioslides, but instead of showing the demo chart from the website,如下所示:

渲染步骤如下:

我的代码很简单:

---
title: "R Markdown Presentation & Plotly"
author: "Eduardo Almeida"
date: "February 19, 2017"
output: ioslides_presentation
---

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

## Interactive plot with Plotly 

```{r}
library(plotly)
p <- plot_ly(economics, x = ~date, y = ~unemploy / pop)
```

正如 Karthik Arumugham 指出的那样,您需要通过输入 p 或不将 plot_ly 分配给变量但直接调用它来显示绘图。

我建议明确说明缺失的变量 (type='scatter', mode='markers') 而不是抑制输出消息。此外,您可以添加 {r, warning=F} 以摆脱

Error: attempt to use zero-length variable name

留言。

---
title: "R Markdown Presentation & Plotly"
author: "Eduardo Almeida"
date: "February 19, 2017"
output: ioslides_presentation
---

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

## Interactive plot with Plotly 

```{r, warning=F}
suppressPackageStartupMessages({library(plotly)})
library(plotly)
plot_ly(economics, x = ~date, y = ~unemploy / pop, type='scatter', mode='markers')
```