Created
August 13, 2024 10:53
-
-
Save vjcitn/1e563d6158e1a820186f6e465766c901 to your computer and use it in GitHub Desktop.
use EBImage to explore spatial transcriptomics data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(EBImage) | |
library(shiny) | |
ui = fluidPage( | |
sidebarLayout( | |
sidebarPanel( | |
helpText("EBImage explorer"), | |
fileInput("inimg", "file"), | |
numericInput("scalefactor", "multfac", min=1, max=50, value=10,step=1), | |
sliderInput("blursig", "sigma for blur", min=1, max=100, value=50) | |
), | |
mainPanel( | |
tabsetPanel( | |
tabPanel("basic", plotOutput("basic")), | |
tabPanel("blur", plotOutput("blurred")), | |
tabPanel("clip", uiOutput("slider1"), uiOutput("slider2"), | |
plotOutput("clipped")), | |
tabPanel("about", verbatimTextOutput("vers")) | |
) | |
) | |
) | |
) | |
server=function(input, output) { | |
getImg = reactive({ | |
validate(need(nchar(input$inimg)>0, "pick img")) | |
EBImage::readImage( input$inimg$datapath ) | |
}) | |
output$basic = renderPlot({ | |
img = getImg() | |
display(img*input$scalefactor, method="raster") | |
}) | |
output$blurred = renderPlot({ | |
img = getImg() | |
display( gblur(img*input$scalefactor, sigma=input$blursig), method="raster") | |
}) | |
output$slider1 = renderUI({ | |
img = getImg() | |
d = dim(img) | |
maxx = d[1] | |
maxy = d[2] | |
sliderInput("xsel", "xlim", min=1, max=maxx, value=c(1, maxx)) | |
}) | |
output$slider2 = renderUI({ | |
img = getImg() | |
d = dim(img) | |
maxx = d[1] | |
maxy = d[2] | |
sliderInput("ysel", "ylim", min=1, max=maxy, value=c(1, maxy)) | |
}) | |
output$clipped = renderPlot({ | |
img = getImg() | |
validate(need(length(input$xsel)>0, "use slider")) | |
display( input$scalefactor*img[ seq(input$xsel[1], input$xsel[2]), seq(input$ysel[1], input$ysel[2]) ], | |
method="raster" ) | |
}) | |
} | |
runApp(list(ui=ui, server=server)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment