我想为R shiny创建一个反应性输入,它会在悬停时返回表格行的row.name
。
在R Shiny中,表格由renderTable
制作,并通过tableOutput
输出。
这应该类似于已经构建的plotID和plotOutput的hoverID(分别用于click& hover)。
我还不太了解JavaScript或jQuery,但仍然按照这些说明自行构建:
http://rstudio.github.io/shiny/tutorial/#building-inputs
谢谢!
更新
这是我到目前为止的jQuery:
$(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);
但input$selectRowBinding
仍然返回NULL。
我很确定我没有正确定义了绑定。
我一直在研究这两种资源:
和