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