DT rows_selected can only return indices now?

869 views
Skip to first unread message

Eric Kostello

unread,
Aug 11, 2015, 6:45:12 PM8/11/15
to Shiny - Web Framework for R
In previous versions of DT, when output$tableID <- renderDataTable ( ..., server = TRUE, ... datatable ( ... rownames = FALSE ) ) the value for tableID_rows_selected would be the values in the first column of the selected row, rather than the index of the selected rows. Is that behavior no longer possible? I get the row indices back either way now.

Thanks

Yihui Xie

unread,
Aug 11, 2015, 6:57:05 PM8/11/15
to Eric Kostello, Shiny - Web Framework for R
Yes, the current development version (0.1.x) of DT always returns
numeric indices. It is a little annoying that it returns different
things depending on whether you use client-side or server-side
processing (moreover, when using server-side processing, you had to
make sure the first column is the row names).

If you do want row names, you can easily obtain them via, e.g.
rownames(data)[input$tableId_rows_selected]. Does that make sense?

Regards,
Yihui

Eric Kostello

unread,
Aug 11, 2015, 7:13:46 PM8/11/15
to Shiny - Web Framework for R, eric.k...@gmail.com
Yes. Mostly I wanted to make sure the switch is permanent before adapting code to work this way. It absolutely makes sense to have consistent behavior. Actually, returning the numeric index is preferable in some situations. Example: I have some data in long form that is uniquely identified by two ids. With the new row indexing behavior I can get both indices easily. With the old behavior I would have had to create a composite ID to unravel which row was clicked.

Thanks,
Eric

Yihui Xie

unread,
Aug 11, 2015, 7:37:12 PM8/11/15
to Eric Kostello, Shiny - Web Framework for R
Yes, it is a permanent switch. Sorry I didn't manage to get rid of
this awkwardness of inconsistency in the first CRAN release of DT.

Regards,
Yihui

mohamma...@multivision.pt

unread,
Jul 5, 2018, 12:15:11 PM7/5/18
to Shiny - Web Framework for R
Hi,
How can I access the data of a DT table? I know that I can have both row and column indices, but how I can use these two to access its data?

row.ind <- input$tableId_rows_selected
col.ind <- input$tableId_columns_selected

DT$data[row.ind,col.ind] ????

Is there any object for a DT data that can be accessible by row and column indices?

Thanks,
Mohammad
Reply all
Reply to author
Forward
0 new messages