Skip to content

refactor exportNetworktoHTML and previewNetwork functions#73

Open
tonywu1999 wants to merge 1 commit intodevelfrom
refactor-viz-cleanup
Open

refactor exportNetworktoHTML and previewNetwork functions#73
tonywu1999 wants to merge 1 commit intodevelfrom
refactor-viz-cleanup

Conversation

@tonywu1999
Copy link
Contributor

@tonywu1999 tonywu1999 commented Feb 27, 2026

Motivation and Context

Please include relevant motivation and context of the problem along with a short summary of the solution.

Changes

Please provide a detailed bullet point list of your changes.

Testing

Please describe any unit tests you added or modified to verify your changes.

Checklist Before Requesting a Review

  • I have read the MSstats contributing guidelines
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • Ran styler::style_pkg(transformers = styler::tidyverse_style(indent_by = 4))
  • Ran devtools::document()

Motivation and Context

This PR refactors the visualization export pipeline for network diagrams in the MSstatsBioNet package. Previously, the code maintained a complex, custom HTML generation workflow that built Cytoscape configurations, generated JavaScript code, and assembled standalone HTML files through multiple intermediate steps (generateCytoscapeConfig, createNodeElements, createEdgeElements, generateJavaScriptCode, and exportCytoscapeToHTML). This refactor simplifies the visualization pipeline by migrating to an htmlwidgets-based approach, which provides a more maintainable and standardized mechanism for saving interactive web-based visualizations. The new implementation leverages the cytoscapeNetwork widget and htmlwidgets::saveWidget for direct HTML export, significantly reducing code complexity (1,330 lines removed) and eliminating bespoke HTML/JavaScript generation.

Changes

Removed Public Functions and Exports:

  • Removed public export of generateCytoscapeConfig from NAMESPACE
  • Removed public function exportCytoscapeToHTML from R/visualizeNetworksWithHTML.R (previously provided standalone HTML export via custom pipeline)
  • Removed internal helper functions: generateCytoscapeConfig, createNodeElements, createEdgeElements, generateJavaScriptCode, and associated utilities
  • Deleted documentation file man/generateCytoscapeConfig.Rd (42 lines)
  • Deleted documentation file man/generateJavaScriptCode.Rd (17 lines)

Modified Functions (Signatures Maintained, Implementation Changed):

  • exportNetworkToHTML(nodes, edges, filename = "network_visualization.html", displayLabelType = "id", nodeFontSize = 12, ...): Now uses cytoscapeNetwork() widget creation followed by htmlwidgets::saveWidget() instead of the previous custom HTML assembly pipeline
  • previewNetworkInBrowser(nodes, edges, displayLabelType = "id", nodeFontSize = 12, ...): Now delegates to the widget-based export mechanism instead of custom HTML generation

Implementation Details:

  • Replaced the end-to-end custom pipeline with direct widget creation and export
  • Eliminated intermediate configuration objects and bespoke HTML/JavaScript construction in favor of the standardized htmlwidgets framework
  • Removed explicit HTML document assembly, embedded JavaScript helpers, custom styling, and inline legend generation
  • Centralized visualization output through htmlwidgets::saveWidget mechanism for both file export and browser preview

File Changes:

  • NAMESPACE: 1 line removed
  • R/visualizeNetworksWithHTML.R: Net change of -1,319 lines (1,330 removed, 11 added)

Unit Tests

The test directory structure exists (tests/testthat), but no information is provided regarding unit tests added or modified in this PR based on the available commit data.

Coding Guidelines

No violations of coding guidelines are evident. The refactor represents best practice improvements:

  • Reducing the public API surface by removing generateCytoscapeConfig and exportCytoscapeToHTML aligns with better encapsulation principles
  • Adopting the standard htmlwidgets framework over custom HTML generation improves alignment with R package best practices and maintainability standards

@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

📝 Walkthrough

Walkthrough

This pull request removes the public export of generateCytoscapeConfig from NAMESPACE and refactors the visualization pipeline from a configuration-based approach to an htmlwidgets-based approach. The custom HTML generation pipeline is replaced with direct usage of cytoscapeNetwork widget and htmlwidgets::saveWidget. Associated documentation files are removed.

Changes

Cohort / File(s) Summary
NAMESPACE Export Removal
NAMESPACE
Removed public export of generateCytoscapeConfig function, reducing the package's public API surface.
Visualization Pipeline Refactor
R/visualizeNetworksWithHTML.R
Replaced config-based HTML generation pipeline (generateCytoscapeConfig, createNodeElements, createEdgeElements, generateJavaScriptCode, exportCytoscapeToHTML) with htmlwidgets-based approach using cytoscapeNetwork widget and htmlwidgets::saveWidget. Functions exportNetworkToHTML and previewNetworkInBrowser now delegate to the widget system. Removed exportCytoscapeToHTML from public API.
Documentation Removal
man/generateCytoscapeConfig.Rd, man/generateJavaScriptCode.Rd
Deleted documentation files for removed/refactored functions. No functional code changes; documentation artifacts only.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Refactor viz #72: Adds the cytoscapeNetwork htmlwidget and htmlwidgets import that this PR refactors to depend upon.
  • Feature html viz #53: Introduced the generateCytoscapeConfig and exportCytoscapeToHTML exports that this PR removes.
  • Filter by PTM site match #68: Previously modified generateCytoscapeConfig documentation and exportNetworkToHTML signature, which this PR further refactors.

Suggested labels

Review effort 2/5

Poem

🐰 The config once sprawled with grand HTML might,
But now a widget bundles all so tight.
Cytoscape sings through htmlwidgets' embrace,
Cleaner exports make the codebase a nicer place!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is entirely empty; all required template sections (Motivation and Context, Changes, Testing, and Checklist items) lack any substantive content. Fill in all required sections: add motivation/context explaining why the refactor is needed, detail the specific changes made, describe testing performed, and confirm completion of the pre-review checklist items.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title refers to a real aspect of the changes but is only partially descriptive; it mentions two functions but omits that the refactor involves removing the old custom HTML/JS pipeline and adopting htmlwidgets instead, which is the main architectural change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-viz-cleanup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
R/visualizeNetworksWithHTML.R (2)

39-39: ⚠️ Potential issue | 🟡 Minor

Same stale documentation and unused ... parameter.

Consistent with exportNetworkToHTML, the ... parameter is documented as being passed to exportCytoscapeToHTML() (which was removed), and is not passed to the exportNetworkToHTML() call on lines 49-52.

🔧 Proposed fix to remove unused parameter
-#' `@param` ... Additional arguments passed to exportCytoscapeToHTML()
 previewNetworkInBrowser <- function(nodes, edges, 
                                     displayLabelType = "id",
-                                    nodeFontSize = 12,
-                                    ...) {
+                                    nodeFontSize = 12) {

Also applies to: 43-43, 49-52

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@R/visualizeNetworksWithHTML.R` at line 39, Remove the stale ... parameter and
its roxygen `@param` documentation from the visualizeNetworksWithHTML.R function
(the documented reference to exportCytoscapeToHTML which no longer exists), and
ensure calls to exportNetworkToHTML(...) do not expect or forward ...; update
the function signature to drop ..., remove the corresponding `@param` ... doc
entry, and clean any internal references that attempted to pass ... to
exportNetworkToHTML so the function and its docs match the actual call pattern.

11-11: ⚠️ Potential issue | 🟡 Minor

Stale documentation and unused ... parameter.

The @param ... documentation references exportCytoscapeToHTML() which was removed in this refactor. The ... parameter is declared but never passed to any function call (cytoscapeNetwork or htmlwidgets::saveWidget).

Either remove the ... parameter entirely or pass it to the underlying functions if additional arguments should be supported.

🔧 Proposed fix to remove unused parameter
-#' `@param` ... Additional arguments passed to exportCytoscapeToHTML()
 #' `@export`
 #' `@return` Invisibly returns the file path of the created HTML file
 exportNetworkToHTML <- function(nodes, edges, 
                                 filename = "network_visualization.html",
                                 displayLabelType = "id",
-                                nodeFontSize = 12,
-                                ...) {
+                                nodeFontSize = 12) {

Also applies to: 18-18

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@R/visualizeNetworksWithHTML.R` at line 11, The roxygen `@param` ... and the
unused dots parameter in visualizeNetworksWithHTML are stale
(exportCytoscapeToHTML was removed) and not forwarded to cytoscapeNetwork or
htmlwidgets::saveWidget; remove the ... parameter from the
visualizeNetworksWithHTML function signature and delete its `@param` ... doc entry
(and any other references to it) so the docs and signature match actual usage,
or alternatively explicitly forward ... to cytoscapeNetwork and/or
htmlwidgets::saveWidget if you want to support extra args (update the roxygen
accordingly); locate the function visualizeNetworksWithHTML and the related
calls to cytoscapeNetwork and htmlwidgets::saveWidget to apply the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@R/visualizeNetworksWithHTML.R`:
- Around line 20-28: The function visualizeNetworksWithHTML is missing the
promised invisible return of the created file path and still declares an unused
... parameter; update the function to return(invisible(filename)) after calling
htmlwidgets::saveWidget (use the existing widget and filename symbols) so
callers receive the file path, and remove or repurpose the ... parameter (and
update previewNetworkInBrowser similarly) so that ... is either deleted from the
function signature and docs or wired to actual downstream calls if additional
args are needed; adjust the roxygen `@return` and `@param` ... docs to match the
final behavior.

---

Outside diff comments:
In `@R/visualizeNetworksWithHTML.R`:
- Line 39: Remove the stale ... parameter and its roxygen `@param` documentation
from the visualizeNetworksWithHTML.R function (the documented reference to
exportCytoscapeToHTML which no longer exists), and ensure calls to
exportNetworkToHTML(...) do not expect or forward ...; update the function
signature to drop ..., remove the corresponding `@param` ... doc entry, and clean
any internal references that attempted to pass ... to exportNetworkToHTML so the
function and its docs match the actual call pattern.
- Line 11: The roxygen `@param` ... and the unused dots parameter in
visualizeNetworksWithHTML are stale (exportCytoscapeToHTML was removed) and not
forwarded to cytoscapeNetwork or htmlwidgets::saveWidget; remove the ...
parameter from the visualizeNetworksWithHTML function signature and delete its
`@param` ... doc entry (and any other references to it) so the docs and signature
match actual usage, or alternatively explicitly forward ... to cytoscapeNetwork
and/or htmlwidgets::saveWidget if you want to support extra args (update the
roxygen accordingly); locate the function visualizeNetworksWithHTML and the
related calls to cytoscapeNetwork and htmlwidgets::saveWidget to apply the
change.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between efbcb1d and abbbb15.

📒 Files selected for processing (4)
  • NAMESPACE
  • R/visualizeNetworksWithHTML.R
  • man/generateCytoscapeConfig.Rd
  • man/generateJavaScriptCode.Rd
💤 Files with no reviewable changes (3)
  • NAMESPACE
  • man/generateJavaScriptCode.Rd
  • man/generateCytoscapeConfig.Rd

Comment on lines +20 to 28
widget <- cytoscapeNetwork(nodes, edges,
displayLabelType = displayLabelType,
nodeFontSize = nodeFontSize)

# Generate configuration
config <- generateCytoscapeConfig(
nodes,
edges,
display_label_type = displayLabelType,
node_font_size = nodeFontSize,
event_handlers = event_handlers
htmlwidgets::saveWidget(
widget,
file = filename,
selfcontained = TRUE
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

cat -n R/visualizeNetworksWithHTML.R

Repository: Vitek-Lab/MSstatsBioNet

Length of output: 2773


🏁 Script executed:

rg -n "cytoscapeNetwork\s*<-\s*function" --type r

Repository: Vitek-Lab/MSstatsBioNet

Length of output: 127


🏁 Script executed:

rg -n "cytoscapeNetwork" --type r -A 3 -B 1

Repository: Vitek-Lab/MSstatsBioNet

Length of output: 6004


Missing return statement breaks documented behavior.

The @return documentation (line 13) states the function "Invisibly returns the file path of the created HTML file", but the function body has no return statement. Any caller relying on this return value will receive NULL.

Additionally, the ... parameter (line 18) is documented as "Additional arguments passed to exportCytoscapeToHTML()", but exportCytoscapeToHTML() was removed in this refactor, and the ... is never used in the function body. This parameter should either be removed or documented with its actual purpose.

Note: The same ... documentation issue exists in previewNetworkInBrowser (line 39).

🐛 Proposed fix to add return statement
     htmlwidgets::saveWidget(
         widget,
         file = filename,
         selfcontained = TRUE
     )
+    
+    invisible(filename)
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@R/visualizeNetworksWithHTML.R` around lines 20 - 28, The function
visualizeNetworksWithHTML is missing the promised invisible return of the
created file path and still declares an unused ... parameter; update the
function to return(invisible(filename)) after calling htmlwidgets::saveWidget
(use the existing widget and filename symbols) so callers receive the file path,
and remove or repurpose the ... parameter (and update previewNetworkInBrowser
similarly) so that ... is either deleted from the function signature and docs or
wired to actual downstream calls if additional args are needed; adjust the
roxygen `@return` and `@param` ... docs to match the final behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant