2017-02-19 73 views
0

我使用Plotly with R创建将在R Markdown Presentation With Ioslides呈现的图表,而是,示出像下面the demo chart from the website- [R降价演示不加载/渲染交互式Plotly图表

enter image description here

据渲染步骤是这样的:

enter image description here

我的代码非常简单:

--- 
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) 
``` 
+1

使用'suppressPackageStartupMessages({library(plotly)})'来避免打包消息。然后在代码的最后一行输入'p'来显示图。 –

+0

这就是答案!谢谢,它工作! –

回答

1

由于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') 
``` 
+0

谢谢,但它仍然无法正常工作。它仍在播放与第二张图片相同的信息。 –

+1

在导入之前添加了suppressPackageStartupMessages({library(plotly)})吗? –

+0

是的,我做到了!现在没关系。我已经接受你的答案。 –