R – data.table grouping using `by`

I have the shiny app with nested tabs in the following order:

  sidebarMenu(
        menuItem("1000.Cash", tabName = "cash1000",
          menuSubItem("CashInHand", tabName = "table1010"),
          menuSubItem("CashInBankAccount", tabName = "table1020"))

where:

menuItem(“1000.Cash”, tabName = “cash1000”) contains the data.table “DF1000”;
menuSubItem(“CashInHand”, tabName = “table1010”) contains the data.table “DF1010”
menuSubItem(“CashInBankAccount”, tabName = “table1020”) contains the data.table “DF1020”

I am trying to construct the following algorithm :

“DF1000” is a higher level data.table wich summmarizes data from both “DF1010” and “DF1020”.
The summarization is to be done in a date range defined by a user with the dateRangeInput() widget.
The dateRangeInput() widget is located inside menuItem(“1000.Cash”, tabName = “cash1000”) as well.

As per conditional summarization shown in the reprex below, when we choose the date range, for instance, between 2020-01-01 and 2021-01-01 we should get the data.table “DF1000” as given below:

   Accounts            Beginning   Debit  Credit  Ending
                       balance                    balance
  1. CashInHand          250         70     50      270
    
  2. CashInBankAccount   250         70     50      270
    
  3. TOTAL:              500         140    100     540
    

However, the code is giving Error in [.data.frame: unused argument (by = DocName).

Can someone help me figure out the way to handle this error?

library(shiny)
library(shinydashboard)
library(rhandsontable)
library(data.table)
library(dplyr)

DF1000 <- data.table(
    "Accounts" = as.character(c("CashInHand", 
                    "CashInBankAccount",
                    "TOTAL:")),
    "Beginning balance" = as.numeric(c(0,0,0)),
    Debit = as.numeric(c(0,0,0)),
    Credit = as.numeric(c(0,0,0)),
    "Ending balance" = as.numeric(c(0,0,0)),
    stringsAsFactors = FALSE)

DF1010 <- data.table(
            "TransactionDate" = as.character(c("01/01/2020", "01/01/2020", "01/01/2021", "01/01/2021")),
            "DocName" = as.character(c("ab", "de","ab", "de")),
        "Beginning balance" = as.numeric(c(100, 150, 105, 155)),
            "Debit" = as.numeric(c(20, 10, 25, 15)),
            "Credit" = as.numeric(c(15, 5, 20, 10)),
            "Ending balance" = as.numeric(c(105, 155, 110, 160)),
                stringsAsFactors = FALSE)

DF1010 <- data.table(
            "TransactionDate" = as.character(c("01/01/2020", "01/01/2020", "01/01/2021", "01/01/2021")),
            "DocName" = as.character(c("lm", "xy","lm", "xy")),
        "Beginning balance" = as.numeric(c(100, 150, 105, 155)),
            "Debit" = as.numeric(c(20, 10, 25, 15)),
            "Credit" = as.numeric(c(15, 5, 20, 10)),
            "Ending balance" = as.numeric(c(105, 155, 110, 160)),
                stringsAsFactors = FALSE)

ui <- fluidPage(
   dashboardPage(
    dashboardHeader(title = "IFRS"),
    dashboardSidebar(
      sidebarMenu(
            menuItem("1000.Cash", tabName = "cash1000",
              menuSubItem("CashInHand", tabName = "table1010"),
              menuSubItem("CashInBankAccount", tabName = "table1020")
        )
      )
    ),

    dashboardBody(
      tabItems(
        tabItem(tabName = "cash1000",
          fluidRow(
            column(
              width = 6,
              label=NULL,
          dateRangeInput("dates1000", "Choose a period:", format = "dd/mm/yyyy",
                     start = "2020-01-01", end = Sys.Date()),
              uiOutput("nested_ui1000")),
            column(
              width = 8,
              "Summary journal: 1000.Cash ",
              rHandsontableOutput("table1000Item1")
              )
             )
       )
     ),
        tabItem(tabName = "table1010",
          fluidRow(
            column(
              width = 8,
              "Journal of entries",
              rHandsontableOutput("table1010Item1")
          )
        )
          ),
        tabItem(tabName = "table1020",
          fluidRow(
            column(
              width = 8,
              "Journal of entries",
              rHandsontableOutput("table1020Item1")
          )
        )
      )
    )
      )
    )


server = function(input, output) {

  data <- reactiveValues()

  observe({
    data$df1000 <- as.data.frame(DF1000)
    data$df1010 <- as.data.frame(DF1010)
    data$df1020 <- as.data.frame(DF1020)

  })

  observe({
    if(!is.null(input$table1000Item1))
      data$df1000<- hot_to_r(input$table1000Item1)
  })

  observe({
    if(!is.null(input$table1010Item1))
      data$df1010<- hot_to_r(input$table1010Item1)
  })

  observe({
    if(!is.null(input$table1020Item1))
      data$df1020<- hot_to_r(input$table1020Item1)
  })

observe({ 
  data$df1000[1, c(2:5)] <- data$df1010[, .(
    "Beginning balance" = sum("Beginning balance", na.rm = TRUE),
    Debit = sum(Debit, na.rm = TRUE),
    Credit = sum(Credit, na.rm = TRUE),
    "Ending balance" = sum("Ending balance", na.rm = TRUE)
  ), by = DocName][, .(
    "Beginning balance" = sum("Beginning balance"),
    Debit = sum(Debit),
    Credit = sum(Credit),
    "Ending balance" = sum("Ending balance")
  )][, c(3:6)]
})

observe({ 
  data$df1000[2, c(2:5)] <- data$df1020[, .(
    "Beginning balance" = sum("Beginning balance", na.rm = TRUE),
    Debit = sum(Debit, na.rm = TRUE),
    Credit = sum(Credit, na.rm = TRUE),
    "Ending balance" = sum("Ending balance", na.rm = TRUE)
  ), by = DocName][, .(
    "Beginning balance" = sum("Beginning balance"),
    Debit = sum(Debit),
    Credit = sum(Credit),
    "Ending balance" = sum("Ending balance")
  )][, c(3:6)]
})

  output$nested_ui1000 <- renderUI({
    if (input$dates1000) {
      dateRangeInput("dates", "Choose a period:", format = "dd/mm/yyyy",
                     start = "2020-01-01", end = Sys.Date())
    } 
  })

  output$table1000Item1 <- renderRHandsontable({
    rhandsontable(data$df1000[c(1:2),c(2:5)], stretchH = "all", rowHeaderWidth = 50, height = 200)
  })

  output$table1010Item1 <- renderRHandsontable({
    rhandsontable(data$df1010, stretchH = "all", rowHeaderWidth = 50, height = 200) |>
      hot_col(1, format = "%d/%m/%Y", type = "date")
  })

  output$table1020Item1 <- renderRHandsontable({
    rhandsontable(data$df1020, stretchH = "all", rowHeaderWidth = 50, height = 200) |>
      hot_col(1, format = "%d/%m/%Y", type = "date")
  })

}

shinyApp(ui = ui, server = server)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật