nvelden / geneviewer

An R package designed for drawing gene arrow maps
https://nvelden.github.io/geneviewer/
Other
26 stars 4 forks source link

Request for feature to save as picture (svg, png) directly from the R package #4

Closed jonng2024 closed 3 months ago

jonng2024 commented 5 months ago

Hi, thanks for developing this library, its a lifesaver for me! Would it be possible to give us the ability to save the chart directly as svg and png please?

If we choose the png option, would it be possible to specify the resolution? This is because I realised that for reasonably complex plots, the resolution is not good enough when I zoom in to look at genes.

Perhaps this library could be connected to ggplot somehow? Thank you =)

nvelden commented 5 months ago

I am working on a better solution but for now you will need to use webshot2 to save the plots like explained here. If you need higher quality images you can increase the zoom.

library(webshot2)

# Generate plot with width and height specifications
cluster_plot <- 
  GC_chart(ophA_clusters, 
           group = "class", 
           cluster = "cluster",
           width = "400px",
           height = "250px")

# Save plot to temp.html file
htmlwidgets::saveWidget(cluster_plot, "temp.html", selfcontained = TRUE)

# Save plot to .png (or .jpg, .jpeg, .webp, .pdf)
webshot2::webshot(
  "temp.html", 
  "output.png", 
  zoom = 2, # Increase zoom for higher resolution
  selector = ".geneviewer")
jonng2024 commented 5 months ago

Ok sure, thank you so much for all your hard work =)

zuzanahalenkova commented 5 months ago

Hi, I have a related issue - is there a way to export the pictures including the links between clusters? The links get lost after exporting to html. I have noticed that they are also missing in the examples at https://nvelden.github.io/geneviewer/reference/GC_links.html. Thank you for this great library!

nvelden commented 5 months ago

What browser are you using? I can see the links on Chrome and Firefox.

zuzanahalenkova commented 5 months ago

I am using Firefox (125.0) on Ubuntu.

zuzanahalenkova commented 5 months ago

Just tried using Chrome and it works, thank you for the tip and for the quick response! :)

nvelden commented 5 months ago

There was an issue the way the links were rendering. They should now also be visible in Firefox. Thanks a lot for pointing this out!