Skip to content

Commit

Permalink
Merge pull request #2 from natverse/feature/interactive-heatmap
Browse files Browse the repository at this point in the history
Add support for interactive heatmap
  • Loading branch information
jefferis authored Mar 9, 2023
2 parents 03c1cf6 + d1c5d97 commit 1e735aa
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
8 changes: 7 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ RoxygenNote: 7.2.3
Imports:
bit64,
checkmate,
glue,
Matrix
Suggests:
covr,
spelling,
testthat (>= 3.0.0)
testthat (>= 3.0.0),
ComplexHeatmap,
InteractiveComplexHeatmap,
kableExtra,
shiny
Language: en-GB
Config/testthat/edition: 3
URL: https://github.com/natverse/coconat,
http://natverse.org/coconat/
BugReports: https://github.com/natverse/coconat/issues
biocViews: Software
35 changes: 35 additions & 0 deletions R/heatmap.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
custom_interactive_heatmap <- function(hm) {
check_package_available('InteractiveComplexHeatmap', repo = 'Bio')
check_package_available('ComplexHeatmap', repo = 'Bio')
check_package_available('kableExtra')
check_package_available('shiny')
ht = ComplexHeatmap::draw(hm)

ui = shiny::fluidPage(
InteractiveComplexHeatmap::InteractiveComplexHeatmapOutput(output_ui = shiny::htmlOutput("info")),
)

click_action = function(df, output) {
output[["info"]] = shiny::renderUI({
if(!is.null(df)) {
shiny::HTML(glue::glue("<p style='background-color:#FF8080;color:white;padding:5px;'>You have clicked on heatmap {df$heatmap}, row {df$row_index}, column {df$column_index}</p>"))
}
})
}
brush_action = function(df, output) {
row_index = unique(unlist(df$row_index))
column_index = unique(unlist(df$column_index))
output[["info"]] = shiny::renderUI({
if(!is.null(df)) {
shiny::HTML(kableExtra::kable_styling(kableExtra::kbl(hm@matrix[row_index, column_index, drop = FALSE], digits = 2, format = "html"), full_width = FALSE, position = "left"))
}
})
}

server = function(input, output, session) {
InteractiveComplexHeatmap::makeInteractiveComplexHeatmap(input, output, session, ht,
click_action = click_action, brush_action = brush_action)
}

shiny::shinyApp(ui, server)
}
12 changes: 12 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
check_package_available <- function(pkg, repo=c("CRAN", "Bioconductor")) {
if(!requireNamespace(pkg, quietly = TRUE)) {
repo=match.arg(repo)
installmsg=switch(repo,
CRAN=paste0("install.packages('",pkg,"')"),
Bioconductor=paste0('if (!require("BiocManager", quietly = TRUE))',
'\n install.packages("BiocManager")',
'\nBiocManager::install("',pkg,'")'))
stop("Please install suggested package: ", pkg, " by doing\n",
installmsg, call. = F)
}
}

0 comments on commit 1e735aa

Please sign in to comment.