I'm trying to build a report dynamically that requires running a loop, and for each iteration printing some messages, tables, and a plot. I can get everything to work except for the plot.
example.rmd
```{r echo=FALSE, results='asis', fig.keep='all', message = FALSE, warning = FALSE}
library(knitr)
library(plotly)
for(i in 1:4){
foo <- iris[sample(nrow(iris), 20), ]
cat("\n")
cat("# Iteration", i, "\n")
# Print the first few lines
print(kable(head(foo)))
cat("\n")
# Plot Sepal.Width vs Petal.Length using ggplotly()
plt <- ggplot(foo, aes(x = Sepal.Width, y = Petal.Length))+geom_point()
# plot(plt) # <- this works
# plot(ggplotly(plt)) # <- this doesn't work
# ggplotly(plt) # <- this doesn't work
cat("\n")
}
```
How can I get the plotly plots to render in my report?