igvteam/igv.js

igv.js With R Shiny

akhilvelluva opened this issue · 2 comments

Has anyone tried the igv.js in R shiny? My app does not respond while pushing the js command. any Idea?
My server code look like this

server <- function(input, output, session) {
observeEvent(input$load_igv_button, {
chr <- input$chr_input
start <- as.numeric(input$start_input)
end <- as.numeric(input$end_input)
region <- paste0(chr, ":", start, "-", end)
bam_file <- paste0("../Bam/", input$sample_name, ".bam")
bai <- paste0("../Bam/", input$sample_name, ".bam.bai")
print(paste("Region:", region))
print(paste("BAM File:", bam_file))

js_code <- sprintf('
  var igvBrowser = document.getElementById("igvFrame").contentWindow.igvBrowser;
  igvBrowser.search("%s");
  igvBrowser.loadTrack({url: "%s",indexURL: %s" ,type:"alignment",format:"bam"});', region, bam_file,bai)

#print("Generated JavaScript code:")
print(js_code)

session$sendCustomMessage(type = "jsCode", js_code)

})
}

I don't know R or shiny but where does this get set?

contentWindow.igvBrowser

Have a look at this project. https://github.com/paul-shannon/igvShiny

Thanks for the suggestion