Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An R markdown presentation does not work whenggplotly in for-loop #1017

Closed
egpivo opened this issue May 19, 2017 · 4 comments
Closed

An R markdown presentation does not work whenggplotly in for-loop #1017

egpivo opened this issue May 19, 2017 · 4 comments

Comments

@egpivo
Copy link

egpivo commented May 19, 2017

Hi there,

The problem is that I want to use a for loop to plot a bunch of interactive ggplotly graphs, which are put into corresponding slides one by one. I've check the issues #273, #425 and #570, but I still can't solve it.

The fail part of script in my.Rmd file is:

---
title: "Automated slides"
output: ioslides_presentation
---

```{r, echo = F, message = FALSE,  results='asis'}
### failed
library(plotly)
plt <- htmltools::tagList()
for(j in 1:2) {
  cat(paste("\n\n## Feature: ",j),"\n\n" ) 
  df <- data.frame(x =  1:10, y = (1:10)^2)
  p <- ggplot(df, aes(x = x, y = y)) + geom_line()
  plt[[j]] <-  ggplotly(p)
}

plt

This is the expected one without a for loop:

### expected
plt <- htmltools::tagList()
for(j in 1:2) {
  p <- ggplot(df, aes(x = x, y = y)) + geom_line()
  plt[[j]] <-  ggplotly(p)
}
cat(paste("\n\n## Feature: ",1),"\n\n" ) 
plt[[1]]
cat(paste("\n\n## Feature: ",2),"\n\n" ) 
plt[[2]]

Any ideas to solve the failed part? Thanks.

@cpsievert
Copy link
Collaborator

Remove the results='asis' bit?

@egpivo
Copy link
Author

egpivo commented May 20, 2017

It doesn't work. Any other suggestions? Thanks.

@cpsievert
Copy link
Collaborator

This is what I get. Perhaps your plots are running off the slide?
screen shot 2017-05-20 at 11 20 37 am

@egpivo
Copy link
Author

egpivo commented May 22, 2017

I think you are perhaps misunderstood my example. I tried to generate every single plot into a singe slide, not all plots in a one slide. In this sense, is there any possible way to solve it? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants