Count the number of rows that match certain criteria in a datatable of a shiny app


#1

I have a simple shiny app:

#ui.r
navbarPage(
  "Application",
  tabPanel("General",
           sidebarLayout(

             sidebarPanel(
               uiOutput("tex2"),
               uiOutput("book1")


              ),
             mainPanel(
               DT::dataTableOutput("hot3"),
               br(),
               rHandsontableOutput("hot5")
             )
           )))

  #server.r
  library(shiny)
library(DT)
library(rhandsontable)
server <- function(input, output,session) {

  output$tex2<-renderUI({
    numericInput("text2","#tests",
                 value = 1,
                 min=1
    )
  })

  output$book1<-renderUI({
    numericInput("bk1", 
                 "Items in test", 
                 value = 1)
  })

  rt1<-reactive({
    data.frame(Sel. = rep(TRUE,input$text2),
               Label=paste("Test",as.integer(1:input$text2)),
               Avail.=as.integer(rep.int(input$bk1,input$text2)),
               Sel =as.integer(rep.int(length(rt2()[,1][rt2()[,1] == TRUE]),input$text2)),
               stringsAsFactors = FALSE)
  })
  output$hot3 <-DT::renderDataTable(
    rt1()

  )


  rt2<-reactive({
    DF=data.frame(
      Sel= rep(TRUE, input$bk1),
      Id= (1:input$bk1),
      Label=paste("Item",1:input$bk1),
      Pf=as.integer(rep.int(0,input$bk1)),
      stringsAsFactors = FALSE
    )
  })
  output$hot5 <-renderRHandsontable({


    rhandsontable(rt2(),width=300,height = 300)


  })
}

As you can see I have 2 numericInput(). The upper one adds one row to the upper Datatable and the lower in the lower rhandsontable. What I want to achieve is to count the number of selected tickboxes in column "Sel" of the rhandsontable and display this number in every row of the column "Sel" of the datatable. But it is now working. When I de-select one tickbox the sum remains the same.
You can find this question on Stackoverflow