I'm trying to bind a network visualization from D3.js to a custom output in Shiny. For some reason, it seems like my rendering functions are not being called. Here is my code:
rbindings.js
var forceNetworkOB = new Shiny.OutputBinding();
forceNetworkOB.find = function(scope) {
return $(scope).find("svg.rio-force-network");
};
forceNetworkOB.renderValue = function(el, graph) {
alert('rendering')
//actual rendering code here...
};
Shiny.outputBindings.register(forceNetworkOB, "jumpy.forceNetworkOB");
CustomIO.R
renderForceNetwork <- function(expr, env=parent.frame(), quoted=FALSE) {
func <- exprToFunction(expr, env, quoted)
function() {
# Never called
browser()
graph <- func()
list(nodes = graph$nodes,
links = graph$edges
)
}
}
forceNetwork <- function(id, width = '400px', height = '400px') {
tag('svg', list(id = id, class = 'rio-force-network', width = width, height = height))
}
ui.R
library(shiny)
source('customIO.R')
shinyUI(fluidPage(
tags$script(src = 'js/d3.min.js'),
tags$script(src = 'js/rbindings.js'),
titlePanel('Network Visualization'),
tabsetPanel(
tabPanel('D3.js Force Layout',
forceNetwork('vis.force', width = '800px', height = '800px'),
)
)
))
and server.R
library(shiny)
source('cytoscape.R')
source('customIO.R')
shinyServer(function(session, input, output) {
# Load the network
network <- networkFromCytoscape('network.cyjs')
output$vis.force <- renderForceNetwork({
# Never called
print('rendering')
browser()
list(
nodes = data.frame(name = network$nodes.data$Label_for_display, group = rep(1, nrow(network$nodes.data))),
edges = data.frame(from = network$edges[,1], to = network$edges[,2])
)
})
})
As you can see from the comments, the browser() lines in my R rendering functions are never called, as well as the alert() in the js rendering function. With some js debugging I can see that my custom binding is correctly giving the svg element to render to as well as its id. This might be something simple but I cannot figure it out.