I would like to build a reactive input for R shiny that returns the row.name
of a table row on hover.
In R Shiny, the table is made with renderTable
and output through tableOutput
.
This should work similar to the already built clickID and hoverID for plotOutput (for click & hover respectively).
I don't quite understand the JavaScript or jQuery well enough yet to follow these instructions and build it myself:
http://rstudio.github.io/shiny/tutorial/#building-inputs
Thank you!
Update:
This is the jQuery I have so far:
$(document).on('hover', '.table-hover tr', function(){
var el = $(this);
$(this).closest("tr").index();
});
var selectRowBinding = new Shiny.InputBinding();
$.extend(selectRowBinding, {
find: function(scope) {
return $(scope).find(".table-hover");
},
getValue: function(el){
return $(el).closest("tr").index();
},
setValue: function(el, value) {
},
subscribe: function(el, callback) {
$(el).on("change.selectRowBinding", function(e) {
callback();
});
},
unsubscribe: function(el) {
$(el).off(".selectRowBinding");
}
});
Shiny.inputBindings.register(selectRowBinding);
but input$selectRowBinding
is still returning NULL.
I'm quite sure I have not properly defined the bindings.
I've been working off of these 2 resources:
and