### List Available Examples Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/InteractiveComplexHeatmap_intro.html Execute htShinyExample() with no arguments to get a list of all available examples shipped with the InteractiveComplexHeatmap package. Individual examples can be run by specifying their index. ```r htShinyExample() ``` -------------------------------- ### Example: Get and redraw heatmap positions Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/htPositionsOnDevice.html This example demonstrates how to draw a heatmap, get its positions on the device, and then redraw it using those positions. This is useful for interactive manipulation or precise placement. ```R if(dev.interactive()) { m = matrix(rnorm(100), 10) ht = Heatmap(m, row_km = 2, column_km = 2) ht = draw(ht) pos = htPositionsOnDevice(ht) InteractiveComplexHeatmap:::redraw_ht_vp(pos) } ``` -------------------------------- ### Interactive heatmap examples Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/htShiny.html Various examples demonstrating how to initialize interactive heatmaps with different configurations and layouts. ```R # use last generated heatmap if(interactive() && dev.interactive()) { m = matrix(rnorm(100), 10) Heatmap(m) htShiny() } # by providing a heatmap/heatmap list if(interactive()) { m = matrix(rnorm(100), 10) rownames(m) = 1:10 colnames(m) = 1:10 ht = Heatmap(m) ht = draw(ht) htShiny(ht) } # vertical heatmap list if(interactive()) { m1 = matrix(rnorm(100), 10) rownames(m1) = 1:10 colnames(m1) = 1:10 ht1 = Heatmap(m1, row_km = 2, column_km = 2) m2 = matrix(sample(letters[1:10], 100, replace = TRUE), 10) ht2 = Heatmap(m2) ht_list = draw(ht1 + ht2) htShiny(ht_list) ht_list = ht1 %v% ht2 htShiny(ht_list) } # compact mode if(interactive()) { m = matrix(rnorm(100), 10) Heatmap(m) htShiny(compact = TRUE) } ``` -------------------------------- ### Run InteractiveComplexHeatmap Examples Source: https://jokergoo.github.io/InteractiveComplexHeatmap/index.html Use the htShinyExample function to launch built-in interactive examples. Specific examples can be accessed by passing the index as an argument. ```R htShinyExample() ``` ```R htShinyExample(1.1) ``` ```R htShinyExample('1.10') ``` -------------------------------- ### Example Usage (No Example Provided) Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/InteractiveComplexHeatmapOutput.html The documentation indicates that there are no direct code examples for this function in this section. Refer to the makeInteractiveComplexHeatmap page for usage. ```R # There is no example NULL #> NULL ``` -------------------------------- ### Run an Interactive Complex Heatmap Example Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/htShinyExample.html Use htShinyExample to run a specific interactive heatmap example. Call htShinyExample() with no arguments to get a list of available examples. ```R htShinyExample(which) ``` -------------------------------- ### Example of NULL Return Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/getPositionFromHover.html This example demonstrates the expected output when no hover event has occurred, returning NULL. ```R NULL #> NULL ``` -------------------------------- ### Launch interactive 2D density visualization Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/interactivate.kde.html Example usage for creating a kde object and launching the interactive interface. ```R if(interactive()) { require(ks) lt = readRDS(system.file("extdata", "2d_density_xy.rds", package = "InteractiveComplexHeatmap")) data = cbind(lt$x, lt$y) fit = kde(data) interactivate(fit) } ``` -------------------------------- ### Interactive Heatmap Position Selection Example Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/selectPosition.html This example demonstrates how to create a heatmap and then select a position interactively. Ensure the heatmap is drawn on an interactive graphics device. ```R if(dev.interactive()) { m = matrix(rnorm(100), 10) rownames(m) = 1:10 colnames(m) = 1:10 ht = Heatmap(m) ht = draw(ht) selectPosition(ht) } ``` -------------------------------- ### Reference sub-heatmap examples Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/subHeatmapOutput.html Refer to the originalHeatmapOutput help page for usage examples. ```R # See examples on the help page of originalHeatmapOutput() ``` -------------------------------- ### Install Latest Version from GitHub Source: https://jokergoo.github.io/InteractiveComplexHeatmap/index.html Install the most recent version of the package directly from GitHub using the devtools package. ```r library(devtools) install_github("jokergoo/InteractiveComplexHeatmap") ``` -------------------------------- ### Install InteractiveComplexHeatmap from Bioconductor Source: https://jokergoo.github.io/InteractiveComplexHeatmap/index.html Use this command to install the package from Bioconductor. Ensure BiocManager is installed first. ```r if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager") BiocManager::install("InteractiveComplexHeatmap") ``` -------------------------------- ### Launch Interactive Shiny Heatmap Example Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/htShinyExample.html Executes a specific interactive heatmap example within an active R Shiny session. ```R if(interactive()) { htShinyExample(4.2) } ``` -------------------------------- ### Shiny App Example for Interactive Heatmap Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/InteractiveComplexHeatmapWidget.html This example demonstrates how to use InteractiveComplexHeatmapWidget within a Shiny application. It sets up a basic UI with a button to trigger heatmap generation and an output area for the heatmap. The server logic creates a heatmap and displays it when the button is clicked. ```R if(interactive()) { require(ComplexHeatmap) ui = fluidPage( actionButton("show_heatmap", "Generate_heatmap"), htmlOutput("heatmap_output") ) server = function(input, output, session) { m = matrix(rnorm(100), 10) ht = Heatmap(m) observeEvent(input$show_heatmap, { InteractiveComplexHeatmapWidget(input, output, session, ht, output_id = "heatmap_output") }) } shiny::shinyApp(ui, server) } ``` -------------------------------- ### Run Specific Interactive Heatmap Example Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/InteractiveComplexHeatmap_intro.html Use `htShinyExample()` to run a specific example by its index. This function makes the interactive heatmap and its source code available on a webpage. ```R htShinyExample(1.4) ``` -------------------------------- ### Shiny App Example for Interactive Heatmap Modal Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/InteractiveComplexHeatmapModal.html This example demonstrates how to use InteractiveComplexHeatmapModal within a Shiny application. It sets up a basic UI with a button to trigger the heatmap modal and a server function that generates a heatmap and displays it when the button is clicked. ```R if(interactive()) { require(ComplexHeatmap) ui = fluidPage( actionButton("show_heatmap", "Generate_heatmap"), ) server = function(input, output, session) { m = matrix(rnorm(100), 10) ht = Heatmap(m) observeEvent(input$show_heatmap, { InteractiveComplexHeatmapModal(input, output, session, ht) }) } shiny::shinyApp(ui, server) } ``` -------------------------------- ### Analyze GO data with GOexpress Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/interactivate_indirect.html Initial setup and execution of GOexpress analysis to prepare data for heatmap visualization. ```R library(GOexpress) data(AlvMac) set.seed(4543) AlvMac_results <- GO_analyse( eSet = AlvMac, f = "Treatment", GO_genes=AlvMac_GOgenes, all_GO=AlvMac_allGO, all_genes=AlvMac_allgenes) BP.5 <- subset_scores( result = AlvMac_results.pVal, namespace = "biological_process", total = 5, p.val=0.05) heatmap_GO( go_id = "GO:0034142", result = BP.5, eSet=AlvMac, cexRow=0.4, cexCol=1, cex.main=1, main.Lsplit=30) ``` -------------------------------- ### Create a Standalone Shiny App with One Interactive Heatmap Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/shiny_dev.html This example demonstrates how to create a basic Shiny app that displays a single interactive heatmap. Ensure ComplexHeatmap, InteractiveComplexHeatmap, and shiny libraries are loaded. ```r library(ComplexHeatmap) library(InteractiveComplexHeatmap) library(shiny) data(rand_mat) # simply a random matrix ht1 = Heatmap(rand_mat, name = "mat", show_row_names = FALSE, show_column_names = FALSE) ht1 = draw(ht1) ui = fluidPage( h3("My first interactive ComplexHeatmap Shiny app"), p("This is an interactive heatmap visualization on a random matrix."), InteractiveComplexHeatmapOutput() ) server = function(input, output, session) { makeInteractiveComplexHeatmap(input, output, session, ht1) } shinyApp(ui, server) ``` -------------------------------- ### Interactive heatmap area selection examples Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/selectArea.html Demonstrates how to use selectArea in an interactive R session with standard and k-means clustered heatmaps. ```R if(dev.interactive()) { m = matrix(rnorm(100), 10) rownames(m) = 1:10 colnames(m) = 1:10 ht = Heatmap(m) ht = draw(ht) selectArea(ht) set.seed(123) ht = Heatmap(m, row_km = 2, column_km = 2) ht = draw(ht) selectArea(ht) } ``` -------------------------------- ### Customizing Heatmap Output with Shiny Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/shiny_dev.html This example demonstrates how to replace the default UI with a custom htmlOutput and define server-side click and brush actions to display styled text and tables of selected heatmap data. Requires the GetoptLong, kableExtra, and InteractiveComplexHeatmap packages. ```R library(GetoptLong) # for the qq() function which does variable intepolation data(rand_mat) ht = Heatmap(rand_mat, show_row_names = FALSE, show_column_names = FALSE) ht = draw(ht) ui = fluidPage( InteractiveComplexHeatmapOutput(output_ui = htmlOutput("info")), ) click_action = function(df, output) { output[["info"]] = renderUI({ if(!is.null(df)) { HTML(qq("

You have clicked on heatmap @{df$heatmap}, row @{df$row_index}, column @{df$column_index}

")) } }) } suppressPackageStartupMessages(library(kableExtra)) brush_action = function(df, output) { row_index = unique(unlist(df$row_index)) column_index = unique(unlist(df$column_index)) output[["info"]] = renderUI({ if(!is.null(df)) { HTML(kable_styling(kbl(m[row_index, column_index, drop = FALSE], digits = 2, format = "html"), full_width = FALSE, position = "left")) } }) } server = function(input, output, session) { makeInteractiveComplexHeatmap(input, output, session, ht, click_action = click_action, brush_action = brush_action) } shinyApp(ui, server) ``` -------------------------------- ### Implement interactive heatmap in a Shiny application Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/makeInteractiveComplexHeatmap.html A complete example demonstrating the integration of a heatmap into a Shiny UI and server function. ```R if(interactive()) { ht = Heatmap(m) ht = draw(ht) ui = fluidPage( InteractiveComplexHeatmapOutput() ) server = function(input, output, session) { makeInteractiveComplexHeatmap(input, output, session, ht) } shiny::shinyApp(ui, server) } ``` -------------------------------- ### Implement Interactive Complex Heatmap in Shiny Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/originalHeatmapOutput.html Demonstrates a full Shiny application setup using originalHeatmapOutput, subHeatmapOutput, and HeatmapInfoOutput within a dashboard layout. ```R if(interactive()) { require(shinydashboard) m = matrix(rnorm(100), 10) ht = Heatmap(m) body = dashboardBody( fluidRow( box(title = "Original heatmap", width = 4, solidHeader = TRUE, status = "primary", originalHeatmapOutput("ht") ), box(title = "Sub-heatmap", width = 4, solidHeader = TRUE, status = "primary", subHeatmapOutput("ht") ), box(title = "Output", width = 4, solidHeader = TRUE, status = "primary", HeatmapInfoOutput("ht") ) ) ) ui = dashboardPage( dashboardHeader(), dashboardSidebar(), body ) server = function(input, output, session) { makeInteractiveComplexHeatmap(input, output, session, ht, "ht") } shinyApp(ui, server) } ``` -------------------------------- ### Creating Interactive Shiny Apps with DESeq2 Data Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/deseq2_app.html This example demonstrates how to use the `interactivate()` function to generate a Shiny app directly from a DESeqDataSet object. Ensure DESeq2 and airway packages are loaded. ```R library(DESeq2) library(airway) data(airway) dds = DESeqDataSet(airway, design = ~ dex) dds = DESeq(dds) interactivate(dds) ``` -------------------------------- ### Implement custom heatmap interactivity in Shiny Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/shiny_dev.html A complete Shiny application example that captures click and brush events on a heatmap to output the selected data. ```R ui = fluidPage( actionButton("action", "Generate heatmap"), plotOutput("heatmap", width = 500, height = 500, click = "heatmap_click", brush = "heatmap_brush"), verbatimTextOutput("output") ) server = function(input, output, session) { ht_obj = reactiveVal(NULL) ht_pos_obj = reactiveVal(NULL) observeEvent(input$action, { m = matrix(rnorm(100), 10) rownames(m) = 1:10 colnames(m) = 1:10 output$heatmap = renderPlot({ ht = draw(Heatmap(m)) ht_pos = htPositionsOnDevice(ht) ht_obj(ht) ht_pos_obj(ht_pos) }) }) observeEvent(input$heatmap_click, { pos = getPositionFromClick(input$heatmap_click) selection = selectPosition(ht_obj(), pos, mark = FALSE, ht_pos = ht_pos_obj(), verbose = FALSE) output$output = renderPrint({ print(selection) }) }) observeEvent(input$heatmap_brush, { lt = getPositionFromBrush(input$heatmap_brush) selection = selectArea(ht_obj(), lt[[1]], lt[[2]], mark = FALSE, ht_pos = ht_pos_obj(), verbose = FALSE) output$output = renderPrint({ print(selection) }) }) } shinyApp(ui, server) ``` -------------------------------- ### Example Usage of interactivateDensity2D Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/interactivateDensity2D.html This example demonstrates how to use the interactivateDensity2D function within an interactive Shiny session. It first reads RDS data and then calls the function with the extracted x and y components. ```R if(interactive()) { lt = readRDS(system.file("extdata", "2d_density_xy.rds", package = "InteractiveComplexHeatmap")) interactivateDensity2D(lt$x, lt$y) } ``` -------------------------------- ### Arrange Multiple Interactive Heatmaps Using Tabsets Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/shiny_dev.html This example demonstrates arranging multiple interactive heatmaps within a Shiny app using tabsets. Each heatmap is placed in a separate tab and requires a unique 'heatmap ID'. ```r ui = tabsetPanel( tabPanel("Numeric", InteractiveComplexHeatmapOutput("heatmap_1")), tabPanel("character", InteractiveComplexHeatmapOutput("heatmap_2")) ) server = function(input, output, session) { makeInteractiveComplexHeatmap(input, output, session, ht1, "heatmap_1") makeInteractiveComplexHeatmap(input, output, session, ht2, "heatmap_2") } shinyApp(ui, server) ``` -------------------------------- ### InteractiveComplexHeatmapModal Function Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/InteractiveComplexHeatmapModal.html This snippet details the InteractiveComplexHeatmapModal function, its arguments, and provides a full example of its implementation in a Shiny application. ```APIDOC ## InteractiveComplexHeatmapModal Function ### Description It creates an interactive heatmap "modal dialog" according to a certain action. The function is normally put inside `observe` or `observeEvent`. ### Method `InteractiveComplexHeatmapModal()` ### Endpoint N/A (This is a function within a Shiny application) ### Parameters #### Arguments - **input** (Shiny input object) - Passed from the Shiny server function. - **output** (Shiny output object) - Passed from the Shiny server function. - **session** (Shiny session object) - Passed from the Shiny server function. - **ht_list** (Heatmap-class or HeatmapList-class object) - A `Heatmap-class` or a `HeatmapList-class` object. - **heatmap_id** (character, optional) - ID of the plot. If it is not specified, an internal ID is assigned. - **title1** (character) - Pass to `InteractiveComplexHeatmapOutput`. Default: "Original heatmap". - **title2** (character) - Pass to `InteractiveComplexHeatmapOutput`. Default: "Selected sub-heatmap". - **width1** (numeric) - Pass to `InteractiveComplexHeatmapOutput`. Default: `ifelse(layout == "1|(2-3)", 800, 450)`. - **height1** (numeric) - Pass to `InteractiveComplexHeatmapOutput`. Default: `ifelse(layout == "1-(2|3)", 700, 350)`. - **width2** (numeric) - Pass to `InteractiveComplexHeatmapOutput`. Default: 370. - **height2** (numeric) - Pass to `InteractiveComplexHeatmapOutput`. Default: 350. - **width3** (numeric) - Pass to `InteractiveComplexHeatmapOutput`. Default: `ifelse(layout == "(1-2)|3", 800, 370)`. - **layout** (character) - Pass to `InteractiveComplexHeatmapOutput`. Default: `ifelse("brush" %in% response, "(1-2)|3", "1-3")`. - **compact** (logical) - Pass to `InteractiveComplexHeatmapOutput`. Default: FALSE. - **action** (character) - Pass to `InteractiveComplexHeatmapOutput`. Default: "click". - **cursor** (logical) - Pass to `InteractiveComplexHeatmapOutput`. Default: TRUE. - **response** (character vector) - Pass to `InteractiveComplexHeatmapOutput`. Default: `c(action, "brush")`. - **brush_opt** (list) - Pass to `InteractiveComplexHeatmapOutput`. Default: `list(stroke = "#f00", opacity = 0.6)`. - **output_ui** (logical) - Pass to `InteractiveComplexHeatmapOutput`. Default: TRUE. - **output_ui_float** (logical) - Pass to `InteractiveComplexHeatmapOutput`. Default: FALSE. - **click_action** (function, optional) - Pass to `makeInteractiveComplexHeatmap`. - **brush_action** (function, optional) - Pass to `makeInteractiveComplexHeatmap`. - **js_code** (character or function) - Additional JavaScript code that is put after the interactive heatmap UI. The value can be a text or a function that takes "heatmap ID" as the argument and returns the formatted JavaScript code. - **close_button** (logical) - Whether to add a close button at the end of the widget. Default: TRUE. - **cancel_action** (character vector) - Whether to remove the UI from HTML or just hide it when the UI is closed. Default: `c("remove", "hide")`. ### Value No value is returned. ### Examples ```r if(interactive()) { require(ComplexHeatmap) ui = fluidPage( actionButton("show_heatmap", "Generate_heatmap"), ) server = function(input, output, session) { m = matrix(rnorm(100), 10) ht = Heatmap(m) observeEvent(input$show_heatmap, { InteractiveComplexHeatmapModal(input, output, session, ht) }) } shiny::shinyApp(ui, server) } ``` ``` -------------------------------- ### Integrate Multiple Interactive Heatmaps in a Single Shiny App Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/shiny_dev.html This example shows how to embed multiple interactive heatmaps in one Shiny app. Each heatmap must be assigned a unique 'heatmap ID' starting with a letter. ```r mat2 = matrix(sample(letters[1:10], 100, replace = TRUE), 10) ht2 = draw(Heatmap(mat2, name = "mat2")) ui = fluidPage( h3("The first heatmap"), InteractiveComplexHeatmapOutput("heatmap_1"), hr(), h3("The second heatmap"), InteractiveComplexHeatmapOutput("heatmap_2") ) server = function(input, output, session) { makeInteractiveComplexHeatmap(input, output, session, ht1, "heatmap_1") makeInteractiveComplexHeatmap(input, output, session, ht2, "heatmap_2") } shinyApp(ui, server) ``` -------------------------------- ### Viewing the Launch Output Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/share.html Executing the launch script provides a local URL to access the interactive heatmap in a web browser. ```bash guz@B069-mb04:~/test_ht$ sh htShiny.sh If the shiny app is not automatically opened in the browser, you can manually copy the following link and paste it to the browser. Listening on http://127.0.0.1:4132 ``` -------------------------------- ### Launching a Shiny Application Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/deseq2_app.html This code snippet shows how to launch a Shiny application using the ui and server components. ```R shinyApp(ui, server) ``` -------------------------------- ### Get Click Position from Heatmap Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/getPositionFromClick.html Use this function to get the coordinates of a click on the heatmap. Ensure the click object is correctly set up in plotOutput. ```R getPositionFromClick(click, ratio = 1) ``` ```R NULL ``` -------------------------------- ### Get Hover Position from Heatmap Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/getPositionFromHover.html Use this function to get the coordinates of a hovered point on the heatmap image. The `hover` argument should be the ID set in `plotOutput`, and `ratio` is the relative resolution. ```R getPositionFromHover(hover, ratio = 1) ``` -------------------------------- ### Interactive visualization of DESeq2 results Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/interactivate.DESeqDataSet.html Demonstrates how to prepare a DESeqDataSet and launch the interactive visualization. ```R if(interactive()) { require(airway) data(airway) se = airway require(DESeq2) dds = DESeqDataSet(se, design = ~ dex) keep = rowSums(counts(dds)) >= 10 dds = dds[keep, ] dds$dex = relevel(dds$dex, ref = "untrt") dds = DESeq(dds) interactivate(dds) } ``` -------------------------------- ### Get Position From Click Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/getPositionFromClick.html Retrieves the coordinates of a clicked point on the heatmap image. ```APIDOC ## GET /getPositionFromClick ### Description Get the position of clicked point on the heatmap image. ### Method GET ### Endpoint /getPositionFromClick ### Parameters #### Query Parameters - **click** (object) - Required - The input click object. Assume `heatmap_click` is the ID set to argument `click` in `plotOutput`, then the value here is `input$heatmap_click`. - **ratio** (numeric) - Optional - The relative resolution. The value should be the ratio between `res` set in `makeInteractiveComplexHeatmap` and 72 (`res/72`). ### Response #### Success Response (200) - **unit** (object) - A `unit` object of length two which are the coordinates of the clicked points. ### See Also `getPositionFromBrush`, `getPositionFromHover`, `getPositionFromDblclick` ``` -------------------------------- ### Get Position from Double Click Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/getPositionFromDblclick.html Retrieves the coordinates of a double-clicked point on the heatmap image. ```APIDOC ## GET /getPositionFromDblclick ### Description Get the position of double clicked point on the heatmap image. ### Method GET ### Endpoint /getPositionFromDblclick ### Parameters #### Query Parameters - **dblclick** (object) - Required - The input dblclick object. Assume `heatmap_dblclick` is the ID set to argument `dblclick` in `plotOutput`, then the value here is `input$heatmap_dblclick`. - **ratio** (numeric) - Optional - The relative resolution. The value should be the ratio between `res` set in `makeInteractiveComplexHeatmap` and 72 (`res/72`). ### Response #### Success Response (200) - **coordinates** (unit object) - A `unit` object of length two which are the coordinates of the double clicked points. ### Response Example ```json { "coordinates": ["100px", "50px"] } ``` ``` -------------------------------- ### Get all row indices from a data frame Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/all_row_indices.html This function retrieves all row indices from the selected data frame. ```APIDOC ## GET /websites/jokergoo_github_io_interactivecomplexheatmap/all_row_indices ### Description Retrieves all row indices from the selected data frame. ### Method GET ### Endpoint /websites/jokergoo_github_io_interactivecomplexheatmap/all_row_indices ### Parameters #### Query Parameters - **df** (data.frame) - Required - The selected data frame. ### Response #### Success Response (200) - **indices** (integer array) - A list of all row indices from the data frame. #### Response Example ```json { "indices": [1, 2, 3, 4, 5] } ``` ``` -------------------------------- ### interactivate Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/interactivate.kde.html Launches an interactive Shiny application for visualizing a 2D density distribution based on a kde object. ```APIDOC ## interactivate ### Description Launches an interactive Shiny application for visualizing a 2D density distribution based on a kde object. ### Method S3 method ### Endpoint interactivate(x, ...) ### Parameters #### Arguments - **x** (kde object) - A `kde` object generated by `kde`. - **...** (Other arguments) - Other arguments that can be passed to the function. ### Request Example __```R if(interactive()) { require(ks) lt = readRDS(system.file("extdata", "2d_density_xy.rds", package = "InteractiveComplexHeatmap")) data = cbind(lt$x, lt$y) fit = kde(data) interactivate(fit) } ``` ``` -------------------------------- ### Get all column indices from the selected data frame Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/all_column_indices.html This function retrieves all column indices from a given data frame. ```APIDOC ## GET /all_column_indices ### Description Retrieves all column indices from the selected data frame. ### Method GET ### Endpoint /all_column_indices ### Parameters #### Query Parameters - **df** (data.frame) - Required - The selected data frame. ### Request Example ```json { "df": "your_data_frame_here" } ``` ### Response #### Success Response (200) - **indices** (list) - A list of column indices. #### Response Example ```json { "indices": [1, 2, 3, 4, 5] } ``` ``` -------------------------------- ### Deploying to Shiny Server Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/share.html Use the rsconnect package to deploy the application to a Shiny Server environment. ```R rsconnect::setAccountInfo(...) rsconnect::deployApp(...) ``` -------------------------------- ### Basic Shiny App with Interactive Heatmap Source: https://jokergoo.github.io/InteractiveComplexHeatmap/index.html Create a simple Shiny app with an interactive heatmap. Requires `InteractiveComplexHeatmap` and `ComplexHeatmap` libraries. `InteractiveComplexHeatmapOutput` is used in the UI and `makeInteractiveComplexHeatmap` in the server. ```r library(InteractiveComplexHeatmap) library(ComplexHeatmap) ht = Heatmap(m) ht = draw(ht) ui = fluidPage( InteractiveComplexHeatmapOutput() ) server = function(input, output, session) { makeInteractiveComplexHeatmap(input, output, session, ht) } shiny::shinyApp(ui, server) ``` -------------------------------- ### Define interactivate method for kde Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/interactivate.kde.html Signature for the S3 method used to launch the interactive Shiny application. ```R # S3 method for kde interactivate(x, ...) ``` -------------------------------- ### Launching the Interactive Heatmap Locally Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/share.html Collaborators can launch the heatmap using the provided shell or batch scripts, or by running the R script directly. ```bash cd ~/test_ht sh htShiny.sh # or Rscript htShiny.R ``` -------------------------------- ### Get Position From Brush Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/getPositionFromBrush.html Retrieves the coordinates of the brushed area on the heatmap image. This function is typically used in conjunction with Shiny applications where brush events are captured. ```APIDOC ## GET /getPositionFromBrush ### Description Get the position of the brushed area on the heatmap image. ### Method GET ### Endpoint /getPositionFromBrush ### Parameters #### Query Parameters - **brush** (object) - Required - The input brush object. Assume `heatmap_brush` is the ID set to argument `brush` in `plotOutput`, then the value here is `input$heatmap_brush`. - **ratio** (numeric) - Optional - The relative resolution. The value should be the ratio between `res` set in `makeInteractiveComplexHeatmap` and 72 (`res/72`). Defaults to 1. ### Response #### Success Response (200) - **list** (list) - A list of length two. The two elements correspond to the coordinates of the two diagonal points. #### Response Example ```json { "coordinates": [ {"x": 10, "y": 20}, {"x": 50, "y": 60} ] } ``` ``` -------------------------------- ### Generate Interactive Heatmap with tidyHeatmap Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/InteractiveComplexHeatmap_intro.html This code demonstrates how to create a tidy heatmap from the mtcars dataset and export it as an interactive Shiny app. Ensure tidyverse and tidyheatmap are installed. ```r library(tidyverse) library(tidyHeatmap) mtcars_tidy <- mtcars %>% as_tibble(rownames="Car name") %>% mutate_at(vars(-`Car name`, -hp, -vs), scale) %>% pivot_longer(cols = -c(`Car name`, hp, vs), names_to = "Property", values_to = "Value") mtcars_heatmap <- mtcars_tidy %>% heatmap(`Car name`, Property, Value ) %>% add_tile(hp) htShiny(mtcars_heatmap) ``` -------------------------------- ### Get heatmap positions on the graphics device Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/htPositionsOnDevice.html Retrieves the positions of heatmap components on the active graphics device. This function is useful for precise layout control and further manipulation of heatmap elements. ```APIDOC ## htPositionsOnDevice ### Description Get heatmap positions on the graphics device. ### Method `htPositionsOnDevice` ### Endpoint N/A (R function) ### Parameters #### Arguments - **ht_list** (HeatmapList-class) - Optional - A `HeatmapList-class` object returned by `draw,Heatmap-method` or `draw,HeatmapList-method`. If it is omitted, it uses the last generated heatmap. - **unit** (string) - Optional - The unit for positioning (e.g., "inch", "cm", "mm", "pt", "native"). - **valueOnly** (boolean) - Optional - Whether only return the numeric values of the positions. - **include_annotation** (boolean) - Optional - Internally used parameter. - **calibrate** (boolean) - Optional - Internally used parameter. ### Details `ht_list` must have been already updated by `draw()` function. The function needs to be executed under a graphics device where the heatmap is written. ### Value It returns a `DataFrame` object of the position of every heatmap slice. ### Request Example ```R if(dev.interactive()) { m = matrix(rnorm(100), 10) ht = Heatmap(m, row_km = 2, column_km = 2) ht = draw(ht) pos = htPositionsOnDevice(ht) InteractiveComplexHeatmap:::redraw_ht_vp(pos) } ``` ### Response Example (DataFrame object with position information) ``` -------------------------------- ### Get heatmap positions on device Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/htPositionsOnDevice.html Retrieves the positions of heatmap slices on the graphics device. Ensure the heatmap has been drawn to the device before calling this function. It returns a DataFrame of slice positions. ```R htPositionsOnDevice(ht_list = get_last_ht(), unit = "inch", valueOnly = FALSE, include_annotation = FALSE, calibrate = TRUE) ``` -------------------------------- ### Generate Dynamic Heatmap in Modal based on Selection Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/shiny_dev.html Demonstrates generating different heatmaps based on user radio button selection within a modal. ```R ui = fluidPage( radioButtons("select", "Select", c("Numeric" = 1, "Character" = 2)), actionButton("show_heatmap", "Generate_heatmap"), ) get_heatmap_fun = function(i) { mat_list = list( matrix(rnorm(100), 10), matrix(sample(letters[1:10], 100, replace = TRUE), 10) ) Heatmap(mat_list[[i]]) } server = function(input, output, session) { observeEvent(input$show_heatmap, { i = as.numeric(input$select) InteractiveComplexHeatmapModal(input, output, session, get_heatmap = get_heatmap_fun(i)) }) } shiny::shinyApp(ui, server) ``` -------------------------------- ### Simulating Position Selection in PDF Device Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/implementation.html Simulates a single click position on a heatmap within a PDF graphics device by providing `pos` argument to `selectPosition()`. The output DataFrame contains the selected point's coordinates and corresponding heatmap data. ```R pdf(...) ht_list = draw(ht_list) pos = selectPosition(ht_list, pos = unit(c(3, 3), "cm")) dev.off() ``` ```R pos ``` -------------------------------- ### Create Interactive Enriched Heatmap (Combined) Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/InteractiveComplexHeatmap_intro.html Exports a combined enriched heatmap with additional heatmaps as a Shiny app. Requires matrices to be normalized. ```r ht = EnrichedHeatmap(mat, ...) + EnrichedHeatmap(...) + Heatmap(...) htShiny(ht) ``` -------------------------------- ### Define UI with Custom Output for Heatmap Actions Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/shiny_dev.html Use `InteractiveComplexHeatmapOutput` with `output_ui` to specify where heatmap interaction outputs should be displayed. This integrates the output directly within the heatmap widget. ```R ui = fluidPage( InteractiveComplexHeatmapOutput(output_ui = htmlOutput("info")) ) ``` -------------------------------- ### Basic usage of htShiny Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/htShiny.html Directly pass a heatmap object or use the last generated heatmap to create an app. ```R htShiny(ht_list) ``` ```R Heatmap(...) + other_heatmaps_or_annotations # or other functions that internally use Heatmap() htShiny() ``` -------------------------------- ### Implement custom heatmap interaction in Shiny Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/from_scratch.html Demonstrates the use of low-level functions to capture click events and retrieve selected heatmap cell information. ```R ui = fluidPage( ..., plotOutput("heatmap", click = "heatmap_click") ) server = function(input, output, session) { ht_obj = reactiveVal(NULL) ht_pos_obj = reactiveVal(NULL) output$heatmap = renderPlot({ ... ht = draw(Heatmap(mat)) ht_pos = htPositionsOnDevice(ht) ht_obj(ht) ht_pos_obj(ht_pos) }) observeEvent(input$heatmap_click, { pos = getPositionFromClick(input$heatmap_click) df = selectPosition(ht_obj(), pos, mark = FALSE, ht_pos = ht_pos_obj(), verbose = FALSE) # do something with `df` ... }) } ``` -------------------------------- ### Integrate with shinydashboard Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/shiny_dev.html Use individual output functions to place heatmap components into separate dashboard boxes. ```R body = dashboardBody( fluidRow( box( title = "Original heatmap", width = 4, solidHeader = TRUE, status = "primary", originalHeatmapOutput("ht", title = NULL) ), box( title = "Sub-heatmap", width = 4, solidHeader = TRUE, status = "primary", subHeatmapOutput("ht", title = NULL) ), box( title = "Output", width = 4, solidHeader = TRUE, status = "primary", HeatmapInfoOutput("ht", title = NULL) ) ) ) ui = dashboardPage( dashboardHeader(), dashboardSidebar(), body ) server = function(input, output, session) { makeInteractiveComplexHeatmap(input, output, session, ht, "ht") } shinyApp(ui, server) ``` -------------------------------- ### Basic Structure for Custom Click/Brush Action Function Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/shiny_dev.html Define a function to handle heatmap interactions. This function receives a DataFrame `df` with selected information and an `output` object to render UI elements. It should include checks for `NULL` df to handle cases where no heatmap body was selected. ```R function(df, output) { output[["info"]] = renderUI({ # or output$info = ... if(is.null(df)) { # have not clicked or brushed into the heatmap body ... } else { ... } }) } ``` -------------------------------- ### htShinyExample Function Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/htShinyExample.html Launches a Shiny application demonstrating interactive complex heatmaps based on the provided index. ```APIDOC ## htShinyExample ### Description Launches a Shiny app that demonstrates interactive complex heatmaps. Each example includes the source code used to generate the application. ### Parameters #### Arguments - **which** (index) - Optional - An index of which example to use. If no argument is provided, the function returns a list of all available examples. ### Value - **Shiny app object** - Returns a Shiny application object. ``` -------------------------------- ### Display Session Information Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/InteractiveComplexHeatmap_intro.html The `sessionInfo()` function displays details about the R session, including version, platform, and loaded packages. This is useful for debugging and reproducibility. ```R sessionInfo() ``` -------------------------------- ### Create Interactive Enriched Heatmap (Single) Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/InteractiveComplexHeatmap_intro.html Exports a single enriched heatmap generated by EnrichedHeatmap() as a Shiny app. Requires a matrix 'mat' to be normalized. ```r mat = normalizeToMatrix(...) ht = EnrichedHeatmap(mat, ...) htShiny(ht) ``` -------------------------------- ### Exporting Interactive Heatmap to a Local Folder Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/share.html Use the save argument in htShiny to generate a directory containing the necessary R scripts and data for offline execution. ```R # E.g. the folder is "test_ht" htShiny(ht, save = "test_ht") ``` -------------------------------- ### Create Interactive OncoPrint (Combined) Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/InteractiveComplexHeatmap_intro.html Exports a combined oncoPrint with additional heatmaps and annotations as a Shiny app. Ensure oncoPrint and Heatmap/rowAnnotation are called with appropriate arguments. ```r ht = oncoPrint(...) + Heatmap(...) + rowAnnotation(...) htShiny(ht) ``` -------------------------------- ### Generate Heatmap List Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/implementation.html Create a list of two heatmaps with k-means clustering applied to the first matrix. ```R library(ComplexHeatmap) library(InteractiveComplexHeatmap) set.seed(123) mat1 = matrix(rnorm(100), 10) rownames(mat1) = colnames(mat1) = paste0("a", 1:10) mat2 = matrix(sample(letters[1:10], 100, replace = TRUE), 10) rownames(mat2) = colnames(mat2) = paste0("b", 1:10) ht_list = Heatmap(mat1, name = "mat_a", row_km = 2, column_km = 2) + Heatmap(mat2, name = "mat_b") ``` -------------------------------- ### Create Interactive Density Heatmap Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/InteractiveComplexHeatmap_intro.html Exports a density heatmap generated by ComplexHeatmap::densityHeatmap() as a Shiny app. Ensure densityHeatmap is called with appropriate arguments. ```r ht = densityHeatmap(...) htShiny(ht) ``` -------------------------------- ### Define UI with Independent Custom Output for Heatmap Actions Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/shiny_dev.html Alternatively, create a separate `htmlOutput` element in the UI to display heatmap interaction results independently of the heatmap widget itself. ```R ui = fluidPage( InteractiveComplexHeatmapOutput(), htmlOutput("info") ) ``` -------------------------------- ### Add CSS for shinydashboard layout Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/shiny_dev.html Include custom CSS to ensure proper overflow and minimum width when using dashboard boxes. ```R body = dashboardBody( fluidRow( box( title = "Original heatmap", width = 4, solidHeader = TRUE, status = "primary", originalHeatmapOutput("ht", title = NULL) ), box( title = "Sub-heatmap", width = 4, solidHeader = TRUE, status = "primary", subHeatmapOutput("ht", title = NULL) ), box( title = "Output", width = 4, solidHeader = TRUE, status = "primary", HeatmapInfoOutput("ht", title = NULL) ), tags$style(" .content-wrapper, .right-side { overflow-x: auto; } .content { min-width:1500px; } ") ) ) ``` -------------------------------- ### Compact Mode for Interactive Heatmaps Source: https://jokergoo.github.io/InteractiveComplexHeatmap/articles/shiny_dev.html Enables compact mode for InteractiveComplexHeatmap, where the output floats to the mouse position upon hovering or clicking. This is equivalent to setting output_ui_float = TRUE and response to include 'brush-output'. ```R InteractiveComplexHeatmapOutput(..., compact = TRUE) ``` ```R InteractiveComplexHeatmap(..., compact = TRUE, output_ui = new_output_ui) ``` -------------------------------- ### Generate the rand_mat dataset Source: https://jokergoo.github.io/InteractiveComplexHeatmap/reference/rand_mat.html Constructs the 60x60 random matrix using normal distributions with specific means and standard deviations. ```R set.seed(123) rand_mat = cbind(rbind(matrix(rnorm(20*20, mean = 1, sd = 0.5), nr = 20), matrix(rnorm(20*20, mean = 0, sd = 0.5), nr = 20), matrix(rnorm(20*20, mean = 0, sd = 0.5), nr = 20)), rbind(matrix(rnorm(20*20, mean = 0, sd = 0.5), nr = 20), matrix(rnorm(20*20, mean = 1, sd = 0.5), nr = 20), matrix(rnorm(20*20, mean = 0, sd = 0.5), nr = 20)), rbind(matrix(rnorm(20*20, mean = 0.5, sd = 0.5), nr = 20), matrix(rnorm(20*20, mean = 0.5, sd = 0.5), nr = 20), matrix(rnorm(20*20, mean = 1, sd = 0.5), nr = 20)) ) + matrix(rnorm(60*60, sd = 0.5), nr = 60) colnames(rand_mat) = paste0("C", 1:60) rownames(rand_mat) = paste0("R", 1:60) ```