0

I am using 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 like the following:

enter image description here

It is rendering the steps like this:

enter image description here

My code is pretty simple:

---
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
  • 1
    Use suppressPackageStartupMessages({library(plotly)}) to avoid package messages. Then type a p in the last line of your code to display the plot. Feb 19, 2017 at 16:14

1 Answer 1

1

As Karthik Arumugham pointed out you need to display the plot, either by entering p or not assigning plot_ly to variable but calling it directly.

I'd suggest to explicitly state the missing variables (type='scatter', mode='markers') instead of suppressing the output messages. In addition you could add {r, warning=F} to get rid of the

Error: attempt to use zero-length variable name

message.

---
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')
```
2
  • Thank you, but it's still not working. It's still shoing the same message as in the second image. Feb 19, 2017 at 17:55
  • 1
    Did you add suppressPackageStartupMessages({library(plotly)}) before the importing plotly? Feb 19, 2017 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.