0

I cannot include plotly figures in a html report in R markdown when the figures are generated from a function.

I can obtain ggplotly figures in a html report in R markdown when ploting them directly without any functions. For instance, kniting the example below:

a <- ggplot(Data, aes_string(x="Category", y=Phenotype)) + geom_violin() + geom_boxplot()
plot(a)
ggplotly(a)

However, when I try to include the graph in a function in order to obtain many graphs from different phenotypes, the figures don't appear in the html report.

Do_graph=function(Data, Phenotype){a<- ggplot(Data, aes_string(x="Category", y=Phenotype)) + geom_violin() + geom_boxplot()
plot(a)
ggplotly(a)}

Phenotypes<-c("A","B","C")
for(Phenotype in Phenotypes){Do_graph(Data, Phenotype)}

Does anyone know how to solve this problem? I've seen some similar issues related to html.widget but I couldn't fix it. Thank you

shafee
  • 15,566
  • 3
  • 19
  • 47
Timoté
  • 3
  • 1
  • Does this answer your question: [Using `ggplotly` and `DT` from a `for` loop in Rmarkdown](https://stackoverflow.com/questions/60685631/using-ggplotly-and-dt-from-a-for-loop-in-rmarkdown/62599342#62599342) [Disclaimer: The answer is from me] – stefan Dec 02 '22 at 15:13

0 Answers0