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. Commented 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')
```
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, but it's still not working. It's still shoing the same message as in the second image.
Did you add suppressPackageStartupMessages({library(plotly)}) before the importing plotly?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.