Reputation: 11
suppose the columns of a data table are: unique-ID, name, salary, position. I display the table in a shiny application using DT::renderdatatable (DT::dataTableOutput). I would like to click on a row of the output to display other data of the person belonging to the ID in another output. what is the solution? in short, how do I extract the unique-ID from a clicked line item?
Upvotes: 1
Views: 2654
Reputation: 8557
You can use the _rows_selected
extension coming with DT
tables. Here's the list of possible arguments. Several live examples are here or here.
This is a simple example of a plot that updates with the lines selected in the table:
library(shiny)
library(DT)
ui <- fluidPage(
DT::dataTableOutput("test_table"),
plotOutput("test_plot")
)
server <- function(input, output, session) {
output$test_table <- DT::renderDataTable({
mtcars
})
output$test_plot <- renderPlot({
s <- input$test_table_rows_selected
if (!is.null(s)) {
plot(mtcars[s, "disp"])
}
})
}
shinyApp(ui, server)
Upvotes: 0