I tried to roll my own roll selector by creating a custom input binding for Shiny, but I've failed so far... perhaps someone (more knowledgeable in JS and Shiny's binding registration process) would know what I might be doing wrong below?
foo.js:
var row_click_binding = new Shiny.InputBinding();
$.extend(row_click_binding, {
find: function(scope) { return $(scope).find("#my_table tbody tr"); },
getId: function(el) { return "my_table"; },
getValue: function(el) { return "my_value" },
setValue: function(el, value) { return null; },
subscribe: function(el, callback) {
$(el).on("click.foo", function(event) {
console.log(this)
callback();
})
},
unsubscribe: function(el) { $(el).off(".foo"); }
})
Shiny.inputBindings.register(row_click_binding);
My understanding (which is obviously wrong) is that the register() call will register the event handlers specified in the subscribe() method.
The "click" event should trigger the row's text to appear on the JS console, but on execution it appears no event is bound to the table's rows.
I've included this file in ui.R, like so:
shinyUI(fluidPage(
tags$head(tags$script(src = "foo.js")),
## rest of Shiny's layout, including the dataTableOutput() call
))
But I've also tried placing the line sourcing "foo.js" at the bottom of the fluidPage() call, thinking perhaps it was trying to bind to DOM elements that didn't exist yet, but no luck at the bottom, either.
Any ideas?
Cheers,
-Murat