Reputation: 43
I am trying to get a specific column value when clicking on a datatable row ,currently I can only get the row number of the clicked row. Eg click on the row to get the id column value rather than the rownum in the below table example.
rownumber first_name second_name id
1 Zeze Steven Sessegnon 192
2 Zlatan Ibrahimovic 272
3 Jack Wilshere 523
server <- function(input, output) {
output$selected_var <- renderText({
paste(length(input$players_rows_selected)) ## This just prints the rownum
})
output$players <- DT::renderDataTable(DT::datatable({
master_playeridlist
}))
}
For the life of me I cannot find how to do this ,
I would imagine it would be something like input$players_rows_selected(id) ?
I had tried adding selection = list(mode = 'single', target = 'column') but this doesn't seem to work, and have read over the options for selection here
Any help here is appreciated.
Upvotes: 0
Views: 572
Reputation: 814
input$foo_rows_selected
stores the row index of the selected rows. To get the value of a specific column for the selected row, simply subset the data frame.
output$selected_var <- renderText({
master_playeridlist[input$players_rows_selected, "id"]
})
Upvotes: 1