title: How to dynamically reorder rows based on input in renderDataTable in R Shiny?
body: <p>I'm asking here because I searched elsewhere and couldn't find an answer.</p>
  
  <p>I'm wondering if/how you can reorder the rows of a datatable using input from R Shiny. The example below actually regenerates the table as the input changes, but I'm hoping that given a change in input, the same action as clicking the relevant sort button would happen. Any ways to achieve this?</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code>library(shiny)
  
  ui = shinyUI(pageWithSidebar(
    headerPanel('Examples of DataTables'),
    sidebarPanel(
  
      radioButtons('var', 'Variable to sort by',
                   c(mpg='mpg',
                     cyl='cyl'),
                   'cyl')
    ),
    mainPanel(
      dataTableOutput("mytable")
    )
  )
  )
  
  server = shinyServer(function(input, output) {
  
    output$mytable = renderDataTable({
      mtcars[order(mtcars[,input$var]),]
    }, options = list(orderClasses = TRUE, LengthMenu = c(5, 25, 50), pageLength = 25))
  
  })
  
  shinyApp(ui,server)
  </code></pre>