Closed lcolladotor closed 3 years ago
Have you figred out the solution to this?
Nope =(
Hi, Leo. c:
I've been playing around with this problem a bit, and this setup seems to work fine. You can check it, and if you like, I can make a pull request later. :) The idea comes from this part of the plotly
manual: https://plotly.com/python/images/#zoom-on-static-images.
library(spatialLIBD)
library(plotly)
# Read spatial experiment -------------------------------------------------
spe <- fetch_data(type = "spe")
# Read specific tissue image ----------------------------------------------
sample_id <- "151507"
image_path <- system.file(
"app", "www", "data", sample_id, "tissue_lowres_image.png",
package="spatialLIBD"
)
img <- png::readPNG(image_path)
# Create ggplot visualization ---------------------------------------------
p <- vis_gene(spe, sample_id, clustervar = "Cluster10X", spatial = FALSE)
# Make it interactive -----------------------------------------------------
# Adjust to size of image to avoid distortion.
img_width <- ncol(img)
img_height <- nrow(img)
layout(
# Convert ggplot to plotly.
ggplotly(
p = p,
width = img_width,
height = img_height
),
# Now add image to background.
images = list(
list(
source = raster2uri(img),
layer = "below",
xanchor = "left",
yanchor = "bottom",
xref = "x",
yref = "y",
sizing = "stretch",
x = 0,
y = -img_height,
sizex = img_width,
sizey = img_height,
opacity = 0.8
)
)
)
I've tried to get the histology background image to work with plotly's zoom functionality but I haven't gotten it to work. Here's some R code I played with:
Related links: