title: R - Shiny Data Table (renderDataTable) reloads to first page when user is on a different page and updates a certain column value (selectInput)
body: <p><strong>PROBLEM:</strong> R Shiny Data Table reloads to the first page whenever user is on a different page of the data table and updates a certain column value (via selectInput).</p>
  
  <p>Hi Stack Users,</p>
  
  <p>In R Shiny, I've created a Shiny application that contains a data table (renderDataTable) where a cell value of column "<em>status</em>" can be updated (via selectInput) by its intended users.</p>
  
  <p>I've prepared a simplified sample of the code below.</p>
  
  <p><strong>ui.R</strong></p>
  
  <pre><code>require(shiny)
  require(shinyjs)
  require(data.table)
  require(dplyr)
  require(DT)
  
  shinyUI(fluidPage(
    useShinyjs(),
    mainPanel("",         
              fluidRow(
                splitLayout(div(DT::dataTableOutput('my_table')), 
                            div(
                              shinyjs::hidden(
                              wellPanel(id="my_panel",
                                        h3("Update Status",align="center"),
                                        htmlOutput("my_status")
                                        )
                              )
                            )
                )
              )
    ) 
  ))
  </code></pre>
  
  <p><strong>server.R</strong></p>
  
  <pre><code>#### DATA PREP AND FUNCTIONS ######################
  id &lt;- c('10001','10002','10003','10004','10005',
          '10006','10007','10008','10009','10010',
          '10011','10012','10013','10014','10015')
  status &lt;- c('OPEN','OPEN','CLOSED','CLOSED','OPEN',
              'OPEN','CLOSED','CLOSED','OPEN','CLOSED',
              'CLOSED','OPEN','OPEN','OPEN','CLOSED')
  dt &lt;- data.table(id=id,status=status)
  
  render_my_table &lt;- function(dt, sel) {
    if(missing(sel)) {
      sel = list(mode='single')
    }  else {
      sel = list(mode='single', selected = sel)
    }
    return (DT::datatable(dt[, list("ID" = id, "Status"=status)], 
                          selection = sel, filter="top", 
                          options = list(sDom  = '&lt;"top"&gt;lrt&lt;"bottom"&gt;ip', 
                                         lengthChange = FALSE, 
                                         pageLength = 5)))
  }
  
  change_status &lt;- function(s_id, s, user, new_dt) {
    if(!(s %in% c('OPEN','CLOSED'))) {
      return (new_dt)
    }
    new_dt[id == s_id, status :=s]
    return (new_dt)
  }
  
  #### SERVER ###############################
  function(input, output, session) {
  
    output$my_table = DT::renderDataTable({
      render_my_table(dt)
    }, server=TRUE)
  
    observeEvent(input$my_table_cell_clicked, {
      row = as.numeric(input$my_table_rows_selected)
      user = dt[row]
      if(nrow(user) == 0) {
        return ()
      }
      session$userData$curr_case &lt;- user$id
      session$userData$curr_row &lt;- row
      output$my_status &lt;- renderUI({ 
        selectInput("my_status", "", c('OPEN','CLOSED'), selected=user$status)
      })
      shinyjs::showElement(id= "my_panel")
    })
  
    observeEvent(input$my_status, {
      if(isTRUE(session$userData$curr_case != "")) {
        new_dt = dt
        current_status = new_dt[id == session$userData$curr_case]$status
        new_status = input$my_status
        if(current_status != new_status) {
          new_dt = change_status(session$userData$curr_case, new_status, new_dt)  
          output$my_table = DT::renderDataTable({
            render_my_table(new_dt, session$userData$curr_row)
          })
        }
      }
    })
  }
  </code></pre>
  
  <p>Basically, once a user selects a row from the table, a hidden panel pops up to the right of the table. This shows a drop down list (selectInput) containing a two choices so that the user can update the value of column status (open to close and vice versa) of the selected row.</p>
  
  <p>Right now, the code works as intended. However, it has <strong>a bug that annoys the users</strong> of the tool. Once a user is on a page, other than page 1, of the data table (e.g. page 2,... to page n) and he/she has updated the status of a row, the change happens but the data table reloads at the first page. </p>
  
  <p>So going back to my problem statement, is there any way I can write the code using R Shiny functions where the user can update the cell real-time (via the drop down list) without the table reloading back to the first page?</p>
  
  <p>I've tried searching here and the internet for days, but until now no luck. Any leads would be appreciated. Thanks!</p>
  
  <p>Miklos </p>