convert a list of plotly plots to an HTML output
2
0
Entering edit mode
3 months ago

Hi Everyone

I have written function that make coverage plots iteratively and saves it in an object (here l). Is there a way to convert list of plotly plots into an HTML output where we have 6 plots in a single row and so on. I want these plots to be interactive because these are coverage plots for aligned bam files for around 20 samples and sometime we intend to inspect regions of dropout by zooming in.

l <- lapply(cov$group, function(x){
 g <-ggplot(df[[x]]) +
  geom_rect(aes(xmin = V2, xmax = V3, ymin = 0, ymax = V4), col="blue", fill="blue")+geom_hline(aes(yintercept = 20))+
    theme_minimal()+theme(axis.text=element_text(size=17),
                          axis.title=element_text(size=17,face="bold"))+xlab(paste(x, "Cov:",percent(round(cov[cov$group==x,]$coverage)/100)))

ggplotly(g)
})

I am aware about subplot but it doesn't accept list of plots like wrap_plots. However wrap_plots doesn't wrap HTML widgets.

I came across these posts but I am not HTML expert so it's kinda hard for me how can I use list of plots as an input:

  1. Post1: https://stackoverflow.com/questions/65606653/r-saving-multiple-html-widgets-together
  2. Post2: https://stackoverflow.com/questions/67591705/saving-r-list-of-plotly-charts-in-html
  3. Or recursive Subplots: https://plotly-r.com/arranging-views.html
ggplot2 bam plotly coverage • 307 views
ADD COMMENT
0
Entering edit mode
3 months ago

I would just follow what they did in this link of yours: https://stackoverflow.com/questions/65606653/r-saving-multiple-html-widgets-together

wiget1 <- ggplotly(g)

or

wiget1 <- l[[1]]

and make a bunch of wigets just like the answer to that question. you may have to figure out the how they are stored via lapply but if in doubt do it manually in a for loop. you probably can do it as below:

doc <- htmltools::tagList(
  div(l[[1], style = "float:left;width:50%;"),
  div(l[[2]],style = "float:left;width:50%;"),
  div(l[[3]], style = "float:left;width:50%;"),
)
## etc...

htmltools::save_html(html = doc, file = "C://Users//Me//Desktop//widgets.html")
ADD COMMENT
0
Entering edit mode

But again that would be manual, I have 400 samples (400 Plots) like this divided into 8 batches and do this manually would take a lot of time.

ADD REPLY
0
Entering edit mode

maybe try:

doc <- htmltools::tagList(lapply(l,function(x) div(x, style = "float:left;width:50%;")))
htmltools::save_html(html = doc, file = "widgets.html")
ADD REPLY
0
Entering edit mode
3 months ago

Have you tried making an html Markdown document?

ADD COMMENT

Login before adding your answer.

Traffic: 999 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6