0

I have some plots to show on the shiny app. I used Plotly to show them. please look at a part of my code. As you can see I added the title and x-axis and y-axis labels for each of the plots. But when I merge them by "subplot", it hides the labels. I need to show all plots at the same time on a page. How can I resolve it?

#UI section
plotlyOutput("fancyPlot")

#Server side
 output$fancyPlot <- renderPlotly({
# I got E somehow, its my dataset 
#I didnt write the lines which I got the other vectors and variables like group1_vectors
for (i in 1: length(s)){
 plot1 = ggplot(E, aes(x = group1 , y = group2)) + 
                labs(title= gene_vectors[i],
                     x= group1_vectors[i], y = group2_vectors[i])+
                geom_point(color='tomato')
              
plot_list_final[[i]] = plot1
}

 plot_list_final =  do.call(tagList, plot_list_final)
            f = length(s)
            p_last <- subplot(plot_list_final[1:f],  nrows = f, margin = 0.045) %>%
              layout(title = "Plots of selected TFs")
            # p_last = p_last + coord_fixed(ratio = 1, xlim = NULL, ylim = NULL, expand = TRUE, clip = "on")
            dev.off()
            
            return(p_last) 
})

shamimash
  • 17
  • 3
  • This is an ongoing issue. [Here's a workaround.](https://stackoverflow.com/questions/59182646/formatting-shiny-plotly-subplots-individual-titles-and-graph-size) – Kat May 05 '22 at 15:54
  • unfortunately, mins are different because in the mentioned issue the number of plots and their location is known, but in my issue the number of plots and their location is unknown. it could be 3 or 10 based on user selection. – shamimash May 05 '22 at 16:53
  • You could use `manipulateWidgets::combineWidgets`. For example,`combineWidgets(list = plot_list_final[1:f], nrow = f, title = "Plots of the selected TFs")`. – Kat May 05 '22 at 20:37
  • Thank you for your help, but I got this erorr: no applicable method for 'plotly_build' applied to an object of class "c('combineWidgets', 'htmlwidget')" – shamimash May 09 '22 at 09:22
  • Sorry about that! For shiny: `combineWidgetOutput` and `renderCombineWidgets`. – Kat May 09 '22 at 13:06
  • sorry, I didn't get it. I used the Plotly function, Do you mean I should use mentioned function instead of Plotly? In addition to the ggplot which you saw in my question, I have some other plots which should be in the Plotly function. – shamimash May 10 '22 at 09:24
  • You ran into the error about the `Plotly` build, that's because `combineWidgets` was not the non-Shiny version; `combineWidgetOutput` and `renderCombineWidgets` are the Shiny version (for both UI and server) of the same function. These are for combining widgets (like a `Plotly` objects). – Kat May 10 '22 at 13:17

0 Answers0