From bf477a9f13a6dda725f14e149fd7da84e5436dbe Mon Sep 17 00:00:00 2001 From: Tony Wu Date: Tue, 2 Sep 2025 16:04:13 -0400 Subject: [PATCH 1/3] add evidenceLink to javascript for opening up indra website --- R/visualizeNetworksWithHTML.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/visualizeNetworksWithHTML.R b/R/visualizeNetworksWithHTML.R index 2c6881e..2f90378 100644 --- a/R/visualizeNetworksWithHTML.R +++ b/R/visualizeNetworksWithHTML.R @@ -264,6 +264,7 @@ createEdgeElements <- function(edges) { "', interaction: '", row$interaction, "', edge_type: '", row$edge_type, "', category: '", row$category, + "', evidenceLink: '", row$evidenceLink, "', color: '", style$color, "', line_style: '", style$style, "', arrow_shape: '", style$arrow, From 41b9866c6c693b63343710f1600243cd21dbfb16 Mon Sep 17 00:00:00 2001 From: Tony Wu Date: Fri, 5 Sep 2025 15:17:08 -0400 Subject: [PATCH 2/3] address coderabbit fix --- R/visualizeNetworksWithHTML.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/visualizeNetworksWithHTML.R b/R/visualizeNetworksWithHTML.R index 2f90378..7ff225a 100644 --- a/R/visualizeNetworksWithHTML.R +++ b/R/visualizeNetworksWithHTML.R @@ -264,7 +264,7 @@ createEdgeElements <- function(edges) { "', interaction: '", row$interaction, "', edge_type: '", row$edge_type, "', category: '", row$category, - "', evidenceLink: '", row$evidenceLink, + "', evidenceLink: '", gsub("(['\\\\])", "\\\\\\1", ifelse(is.na(row$evidenceLink), "", row$evidenceLink)), "', color: '", style$color, "', line_style: '", style$style, "', arrow_shape: '", style$arrow, From 240951ccf534c3a081efaa7752f1a513915a4068 Mon Sep 17 00:00:00 2001 From: Tony Wu Date: Fri, 5 Sep 2025 15:32:04 -0400 Subject: [PATCH 3/3] escape json string with better readability --- R/visualizeNetworksWithHTML.R | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/R/visualizeNetworksWithHTML.R b/R/visualizeNetworksWithHTML.R index 7ff225a..cd4772b 100644 --- a/R/visualizeNetworksWithHTML.R +++ b/R/visualizeNetworksWithHTML.R @@ -257,6 +257,11 @@ createEdgeElements <- function(edges) { # Get styling for this edge style <- getEdgeStyle(row$interaction, row$category, row$edge_type) + # Sanitize optional evidenceLink + evidence_link <- if ("evidenceLink" %in% names(row)) row$evidenceLink else NA_character_ + evidence_link <- ifelse(is.na(evidence_link) | evidence_link == "NA", "", evidence_link) + evidence_link <- escape_js_string(evidence_link) + # Create edge data with styling information edge_data <- paste0("{ data: { source: '", row$source, "', target: '", row$target, @@ -264,7 +269,7 @@ createEdgeElements <- function(edges) { "', interaction: '", row$interaction, "', edge_type: '", row$edge_type, "', category: '", row$category, - "', evidenceLink: '", gsub("(['\\\\])", "\\\\\\1", ifelse(is.na(row$evidenceLink), "", row$evidenceLink)), + "', evidenceLink: '", evidence_link, "', color: '", style$color, "', line_style: '", style$style, "', arrow_shape: '", style$arrow, @@ -276,6 +281,17 @@ createEdgeElements <- function(edges) { return(edge_elements) } +# Helper to safely embed strings into JS single-quoted literals +escape_js_string <- function(x) { + if (is.null(x)) return("") + x <- as.character(x) + x <- gsub("\\\\", "\\\\\\\\", x) # backslashes + x <- gsub("'", "\\\\'", x) # single quotes + x <- gsub("\r", "\\\\r", x) + x <- gsub("\n", "\\\\n", x) + x +} + #' Generate Cytoscape visualization configuration #' #' This function creates a complete Cytoscape configuration object that can be