2017-02-19 65 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

是的,我做到了!現在沒關係。我已經接受你的答案。 –