refactor(networks): Refactor visualization suite to enable download of PNG files#173
refactor(networks): Refactor visualization suite to enable download of PNG files#173tonywu1999 merged 10 commits intodevelfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
💤 Files with no reviewable changes (3)
📝 WalkthroughWalkthroughRefactors the network visualization module to remove Shiny-specific inline Cytoscape JS and custom message wiring. The server now exposes a reactive Changes
Sequence Diagram(s)sequenceDiagram
participant Browser as Client (Browser)
participant Shiny as Server (visualizeNetworkServer)
participant MSBN as MSstatsBioNet
participant FS as File / HTML widget
Browser->>Shiny: load UI (cytoscapeNetworkOutput)
Shiny->>MSBN: renderCytoscapeNetwork(nodes, edges, displayLabelType)
MSBN-->>Browser: HTML widget (interactive network)
Browser->>Shiny: user clicks node/edge -> inputs `network_node_clicked` / `network_edge_clicked`
Shiny->>Shiny: observe inputs -> highlight table rows / update state
Shiny->>FS: export action -> htmlwidgets::saveWidget(cytoscapeNetwork, file.html)
FS-->>Browser: download / open preview
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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. Comment |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 568-575: The rendered network uses a snapshot (render_data) for
display but the click handlers read the live renderNetwork() inputs, causing
mismatches; persist the displayed network snapshot (e.g., assign the snapshot
produced for output$network to a reactiveVal or reactiveValues like
displayedNetworkSnapshot) when creating the cytoscapeNetwork in output$network,
and update the click/selection observers to read from that persisted
displayedNetworkSnapshot instead of calling renderNetwork() (also update the
other observers referenced around the block handling clicks at the later section
currently reading renderNetwork()); ensure the snapshot contains both
nodes_table and edges_table and is updated only when the Display Network action
is performed so clicks map to the shown graph.
| output$network <- MSstatsBioNet::renderCytoscapeNetwork({ | ||
| MSstatsBioNet::cytoscapeNetwork( | ||
| nodes = render_data$nodes_table, | ||
| edges = render_data$edges_table, | ||
| nodeFontSize = 12, | ||
| displayLabelType = input$displayLabelType | ||
| ) | ||
| }) |
There was a problem hiding this comment.
Persist rendered network data to keep click highlighting in sync.
output$network is rendered from a snapshot created on Display Network, but the click handlers read renderNetwork() (live inputs). If inputs change after rendering, edge/node clicks can map against a different dataset than what is shown.
💡 Suggested fix (cache displayed network snapshot and reuse it in click observers)
# Reactive value to store search results
proteinSearchResults <- reactiveVal(NULL)
+
+ # Snapshot of the network currently displayed in the UI
+ displayedNetworkData <- reactiveVal(NULL)
@@
render_data <- networkVisualization()
if (is.null(render_data)) {
# Hide loading indicator and re-enable button if there's an error
shinyjs::hide("loadingIndicator")
shinyjs::enable("showNetwork")
return()
}
+ displayedNetworkData(render_data)
@@
observeEvent(input$network_edge_clicked, {
edge_data <- input$network_edge_clicked
- network_data <- renderNetwork()
+ network_data <- displayedNetworkData()
req(network_data)
edges_table <- network_data$edges_table
highlightEdgeInTable(output, edge_data, edges_table)
})
@@
observeEvent(input$network_node_clicked, {
node_data <- input$network_node_clicked
- network_data <- renderNetwork()
+ network_data <- displayedNetworkData()
req(network_data)
nodes_table <- network_data$nodes_table
highlightNodeInTable(output, node_data, nodes_table)
})Also applies to: 612-627
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@R/module-visualize-network-server.R` around lines 568 - 575, The rendered
network uses a snapshot (render_data) for display but the click handlers read
the live renderNetwork() inputs, causing mismatches; persist the displayed
network snapshot (e.g., assign the snapshot produced for output$network to a
reactiveVal or reactiveValues like displayedNetworkSnapshot) when creating the
cytoscapeNetwork in output$network, and update the click/selection observers to
read from that persisted displayedNetworkSnapshot instead of calling
renderNetwork() (also update the other observers referenced around the block
handling clicks at the later section currently reading renderNetwork()); ensure
the snapshot contains both nodes_table and edges_table and is updated only when
the Display Network action is performed so clicks map to the shown graph.
Motivation and Context
This PR refactors the network visualization module to decouple Cytoscape rendering from Shiny-specific logic and to enable downloading/exporting networks as standalone HTML/PNG artifacts. Previously the module generated inline JavaScript with embedded Shiny bindings and used custom message passing and event wiring. The refactor delegates rendering to MSstatsBioNet (using cytoscapeNetwork and renderCytoscapeNetwork), simplifies UI containers, and exposes a reactive network output so the visualization can be saved via htmlwidgets::saveWidget (enabling PNG/HTML export workflows).
Detailed Changes
R/module-visualize-network-server.R
R/module-visualize-network-ui.R
NAMESPACE
Documentation
Tests
Public API / Contract changes
Unit tests added or modified
Coding Guidelines Violations