Ask Your Question
3

How can I obtain the row that has been selected in the Shiny DT?

asked 2021-10-03 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-09-28 04:00:00 +0000

plato gravatar image

You can use the input$tableId_rows_selected variable to obtain the rows that have been selected in the Shiny DT. "tableId" should be replaced with the ID of the DT.

Here is an example code snippet for obtaining the selected rows:

output$selectedRows <- renderText({
  selected <- input$tableId_rows_selected
  if (length(selected) == 0) {
    "No rows selected."
  } else {
    paste("Selected row(s): ", paste(selected, collapse = ", "))
  }
})

This code will display the index(es) of the selected row(s) if any rows are selected, otherwise it will display "No rows selected."

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-10-03 11:00:00 +0000

Seen: 10 times

Last updated: Sep 28 '22