Skip to content

chore(moduleServer): use more modern module server for network server#172

Merged
tonywu1999 merged 2 commits intodevelfrom
refactor-network
Feb 25, 2026
Merged

chore(moduleServer): use more modern module server for network server#172
tonywu1999 merged 2 commits intodevelfrom
refactor-network

Conversation

@tonywu1999
Copy link
Contributor

@tonywu1999 tonywu1999 commented Feb 25, 2026

Motivation and Context

This PR modernizes the network visualization server by migrating from Shiny's older callModule pattern to the contemporary moduleServer pattern. The change aligns the package with current Shiny best practices, improves namespacing and composability of server logic, and clarifies the public API for initializing the network module.

Solution Summary

Refactor visualizeNetworkServer into a Shiny module initializer using moduleServer, update invocation sites and documentation, add the required NAMESPACE import for moduleServer, and set a minimum shiny version in DESCRIPTION.

Detailed Changes

  • NAMESPACE

    • Added: importFrom(shiny, moduleServer)
  • R/module-visualize-network-server.R

    • Refactored visualizeNetworkServer from a traditional server function:
      • Old signature: visualizeNetworkServer(input, output, session, parent_session, dataComparison)
      • New signature: visualizeNetworkServer(id, parent_session, dataComparison)
    • Wrapped implementation inside moduleServer(id, function(input, output, session) { ... })
    • Converted internal use to module-scoped Shiny objects (input/output/session) and retained parent_session where needed.
    • Preserved core logic: data loading, label/protein updates, network generation, event handlers, Cytoscape JS generation, table rendering, and helpers.
    • Kept helper functions (generateCytoscapeJSForShiny, renderDataTables, highlightNodeInTable, highlightEdgeInTable, openEvidenceLink, loadCsvData, updateLabelChoices, etc.) in the file; adjusted context to module usage.
    • Minor documentation/roxygen updates to reflect id parameter and module semantics.
    • Added explicit end-module comment for clarity.
  • R/server.R

    • Replaced callModule invocation for the network module with direct moduleServer-style initializer:
      • Old: callModule(visualizeNetworkServer, "network", session, data_comparison)
      • New: visualizeNetworkServer("network", parent_session = session, dataComparison = data_comparison)
    • Uses named parameters parent_session and dataComparison at the call site.
    • Left other module invocations unchanged (qc still uses callModule; loadpage and statmodel use direct module-style calls when already refactored).
  • man/visualizeNetworkServer.Rd

    • Updated usage and arguments to reflect new signature:
      • New usage: visualizeNetworkServer(id, parent_session, dataComparison)
      • Replaced documented parameters input/output/session with id (Module ID string); retained parent_session and dataComparison.
  • DESCRIPTION

    • Updated Imports to require shiny (>= 1.5.0).

Unit Tests

  • Existing tests in tests/testthat/test_network_visualization.R exercise:
    • generateCytoscapeJSForShiny and other helpers (filterDataByLabel, getInputParameters, annotateProteinData, extractSubnetwork, etc.)
    • Mocked MSstatsBioNet interactions via mockery.
  • No new tests were added or existing tests modified in this PR to explicitly verify the moduleServer refactor of visualizeNetworkServer or its new initialization pattern. Current tests continue to validate helper functions used by the module.

Coding Guidelines / Potential Issues

  • Public API change: visualizeNetworkServer's signature changed from (input, output, session, parent_session, dataComparison) to (id, parent_session, dataComparison). This is a breaking change for any external code that directly called the old signature; callers must now initialize the module via visualizeNetworkServer("id", parent_session = session, dataComparison = ...). Update any third-party usages accordingly.
  • DESCRIPTION now requires shiny >= 1.5.0. Ensure this minimum version is acceptable for target users/environments.
  • Minor stale comment: R/server.R contains an outdated comment about keeping callModule for non-refactored modules. Consider removing or updating it (the network module has been refactored).
  • No unit tests were added to assert the moduleServer wiring or the new call-site behavior — consider adding tests that instantiate the module in a mock Shiny session to verify integration.

@coderabbitai
Copy link

coderabbitai bot commented Feb 25, 2026

📝 Walkthrough

Walkthrough

visualizeNetworkServer is converted to a Shiny module: signature changed to accept id (module ID) and implementation wrapped with moduleServer. Call sites, NAMESPACE import, DESCRIPTION, and man page updated to reflect the module-based API and a shiny version constraint.

Changes

Cohort / File(s) Summary
NAMESPACE
NAMESPACE
Added importFrom(shiny, moduleServer) to enable moduleServer usage.
Module Server Implementation
R/module-visualize-network-server.R
Reworked visualizeNetworkServer signature from (input, output, session, parent_session, dataComparison) to (id, parent_session, dataComparison) and wrapped implementation with moduleServer(id, function(input, output, session) { ... }). Internal logic moved into module scope and namespacing applied.
Server Call Site
R/server.R
Replaced callModule(visualizeNetworkServer, "network", session, data_comparison) with visualizeNetworkServer("network", parent_session = session, dataComparison = data_comparison) to match new module initializer style.
Documentation / Man Page
man/visualizeNetworkServer.Rd
Updated Rd to reflect new function signature visualizeNetworkServer(id, parent_session, dataComparison), removing input, output, session params and documenting id.
Package Metadata
DESCRIPTION
Bumped shiny dependency to shiny (>= 1.5.0) in Imports.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hopped through code with nimble feet,
Wrapped a server in a module neat,
Gave it an id, a tidy home,
Now namespaced fields can safely roam,
Hooray for shiny, slim and sweet ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The PR title accurately describes the main change: refactoring visualizeNetworkServer to use Shiny's modern moduleServer pattern instead of the legacy callModule approach.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-network

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.

@github-actions
Copy link

Failed to generate code suggestions for PR

@tonywu1999 tonywu1999 marked this pull request as ready for review February 25, 2026 15:55
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

🧹 Nitpick comments (1)
R/server.R (1)

64-65: Update stale inline comment near the new module call.

Line 65 is already using the refactored call style, but Line 64 still references callModule.

Suggested cleanup
-  # visualizeNetworkServer - keep callModule if not yet refactored
+  # visualizeNetworkServer - module-style invocation
   visualizeNetworkServer("network", parent_session = session, dataComparison = data_comparison)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@R/server.R` around lines 64 - 65, Update the stale inline comment above the
module invocation: replace or remove the "keep callModule if not yet refactored"
note since the code already uses the refactored call
visualizeNetworkServer("network", parent_session = session, dataComparison =
data_comparison); ensure the comment references the current refactored usage (or
remove it entirely) so the inline comment accurately reflects the use of
visualizeNetworkServer rather than mentioning callModule.
🤖 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/module-visualize-network-server.R`:
- Around line 319-320: The DESCRIPTION Imports currently lists shiny without a
version; because visualizeNetworkServer uses moduleServer (which requires shiny
>= 1.5.0), update DESCRIPTION to require Shiny >= 1.5.0 by modifying the Imports
entry for shiny to "shiny (>= 1.5.0)" so package installs/loaders on older
systems will pull a compatible Shiny version.

---

Nitpick comments:
In `@R/server.R`:
- Around line 64-65: Update the stale inline comment above the module
invocation: replace or remove the "keep callModule if not yet refactored" note
since the code already uses the refactored call
visualizeNetworkServer("network", parent_session = session, dataComparison =
data_comparison); ensure the comment references the current refactored usage (or
remove it entirely) so the inline comment accurately reflects the use of
visualizeNetworkServer rather than mentioning callModule.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75ce6c2 and d29e06b.

📒 Files selected for processing (4)
  • NAMESPACE
  • R/module-visualize-network-server.R
  • R/server.R
  • man/visualizeNetworkServer.Rd

@tonywu1999 tonywu1999 changed the title use more modern module server for network chore(moduleServer): use more modern module server for network server Feb 25, 2026
@tonywu1999 tonywu1999 merged commit 94155dc into devel Feb 25, 2026
2 checks passed
@tonywu1999 tonywu1999 deleted the refactor-network branch March 5, 2026 16:01
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