I have the shiny app below in which I click on datatable row and display its index next to it. Is it possible to press the Next
button and display the index of the next row? The table's next row will be highlighted accordingly everytime as well.
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(
title = 'Select Table Rows',
h1('A Server-side Table'),
fluidRow(
column(9, DT::dataTableOutput('x3')),
column(3, verbatimTextOutput('x4')),
actionButton("next","Next row")
)
),
server = function(input, output, session) {
# server-side processing
mtcars2 = mtcars[, 1:8]
output$x3 = DT::renderDataTable({datatable(selection = list(target = "row", mode = "single"),mtcars2 )})
# print the selected indices
output$x4 = renderPrint({
s = input$x3_rows_selected
if (length(s)) {
cat('These rows were selected:\n\n')
cat(s, sep = ', ')
}
})
})