Get Selected Row From DataTable in Shiny App

前端 未结 3 1671
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 01:57

I want to modify this application:

https://demo.shinyapps.io/029-row-selection/

so that only one row can be selected at a time, and so that I can acquire the

3条回答
  •  再見小時候
    2020-12-14 02:11

    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.

提交回复
热议问题