I have a render plotly function in which I get some plots of a loop, how can I plot all of them at the same time?
please see a part of my code:
please notice this code is inside of a render plotly
plot_list_final = list()
for (i in 1: length(s)) {
Final_fig_box <- subplot(plot_list1[[i]], plot_list2[[i]])%>%
layout(title = "Inferred Celltype Activity")
plot_list_final[[i]] = Final_fig_box
return(plot_list_final[[i]])
}
I would like to have all plots on a page at the same time, but the code shows only the last plot (last i).
Thanks in advance
Seems you have two issues.
Not disposing of all but the last plot that you collate
Then generating a ui capable of displaying all the kept plots.
Ill help you directly with the first part, but the second i recommend you read up on dynamic UI and make a reprex if you want further help with.
plot_list_final = list()
for (i in 1: length(s)) {
Final_fig_box <- subplot(plot_list1[[i]], plot_list2[[i]])%>%
layout(title = "Inferred Celltype Activity")
plot_list_final[[i]] = Final_fig_box
}
return(plot_list_final)
}
Yes, I have realized that I should have separate plot functions in UI section to show all figures together, but my question is: for example if I have 5 plots (i is 5 in the above code), how can I write to add 5 plot functions in UI?
I don't know the syntax!
Is it possible to automatically add UI elements based on the server part's output?
Is the number of plots fixed or variable?
You could use "insertUI" to insert some elements, e.g. the plots that you could label "plot1", "plot2", "plot3" etc, however I think this isn't very elegant.
The easiest strategy would be to merge all plots into one figure and just show this!?
Did you consider using facet_wrap?
Also the cowplot-library allows to arrange multiple plots into one, here the plot_grid function might be useful when the plots are already stored in a list.