UPDATE: you can now access the selected rows using input$tableId_rows_selected
in server.R
. See here for more details.
To select a unique row, you can change the callback function of your example to this:
callback = "function(table) {
table.on('click.dt', 'tr', function() {
table.$('tr.selected').removeClass('selected');
$(this).toggleClass('selected');
Shiny.onInputChange('rows',
table.rows('.selected').data()[0][0]);
});
}"
When you click on a row,it basically removes any selected rows (they have the .selected class) and selects the row you clicked on.
I also changed the code in the Shiny.onInputChange function so that it returns the number in the first column.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…