$中的错误:“ closure”类型的对象不可子集化,我该如何解决?

时间:2019-04-17 12:00:21

标签: r shiny shinydashboard shiny-reactivity

我已经上传了两个csv,并且正在reactive()中使用shinyr来操纵csv数据。但是出现此错误

  

$中的错误:类型为'closure'的对象不可设置

我对R还是很陌生,如何克服这个错误?谢谢

    ##datasets
    datatables
                 Client Amount     Reason
    1 0000001440MACT800 100000  6866755276

    datatable
                CLIENTID UPDATED.BY DEPOSIT.TYPE       AMOUNT       UPDATED.ON
    1  0000001451MACT800      ADMIN Cash-Deposit   100,000.00  7/14/2016 09:33
    2  0000001002MACT800      ADMIN Cash-Deposit   100,000.00  7/14/2016 09:23
    3  0000001006MACT800      ADMIN Cash-Deposit 1,500,000.00  10/3/2016 11:48
    4  0000001440MACT800      ADMIN Cash-Deposit   100,000.00  7/12/2016 14:13
    5  0000001022MACT800      ADMIN Cash-Deposit   150,000.00  10/6/2016 14:23
    6  0000001024MACT800      ADMIN Cash-Deposit   100,000.00  7/20/2016 08:18
    7  0000001032MACT800      ADMIN Cash-Deposit   100,000.00  7/20/2016 08:17
    8  0000001034MACT800      ADMIN Cash-Deposit    50,000.00  7/20/2016 08:29
    9  0000001037MACT800      ADMIN Cash-Deposit   100,000.00  7/20/2016 08:17
    10 0000001440MACT800      ADMIN Cash-Deposit 1,000,000.00  11/3/2016 14:40
    11 0000001053MACT800      ADMIN Cash-Deposit 1,000,000.00  11/3/2016 14:51
    12 0000001053MACT800      ADMIN Cash-Deposit 5,000,000.00  11/9/2016 15:02
    13 0000001082MACT800      ADMIN Cash-Deposit   500,000.00  11/2/2016 12:47
    14 0000001451MACT800      ADMIN Cash-Deposit 7,000,000.00 11/15/2016 13:12
    15 0000001099MACT800      ADMIN Cash-Deposit 6,404,564.00 11/17/2016 14:23
    16 0000001101MACT800      ADMIN Cash-Deposit    50,000.00  11/2/2016 12:50

function(input, output, session) {    
             dhh  <- reactive({
                inFile <- input$file
                if (is.null(inFile)) return(NULL)
                datatables <- read.csv(input$file[[1, 'datapath']], check.names=FALSE)
                return(datatables)
              })

      output$terry <- renderDataTable({
        if (is.null(dhh)) return(NULL)
        datatables <- data.frame(dhh())
        datatables
      })

              mk <- reactive({
                if (is.null(input$file)) return(NULL)
                inFile <- input$file
                datatable <- read.csv(input$file[[2, 'datapath']], check.names=FALSE)
                return(datatable) 
              })

      output$contents <- renderDataTable({
        if (is.null(mk)) return(NULL)
        datatable <- data.frame(mk())
        datatable
      })

            gloria <- reactive({
                alice <- dhh()
                calvin <- mk()
                x1=calvin[order(nrow(calvin):1),] #invert row order
                ppp <- as.character(alice$Client )
                non <- data.frame(calvin$CLIENTID)
                vcv <- c(ppp)  
                tttt <- as.vector(non)

                r <- calvin[non %in% vcv, ] 

                pipo <- r %>% 
                  mutate(UPDATED.ON=as.Date(factor(r$UPDATED.ON), format = "%m/%d/%Y"))%>% 
                  group_by(r$CLIENTID) %>%  
                  arrange(desc(UPDATED.ON)) %>%
                  slice(1)

         #calculate difference in days
            y <- pipo$UPDATED.ON
            tr <- as.Date(factor(y), format = "%Y/%m/%d")
            jp <- Sys.Date()
            ty <- as.numeric(difftime(Sys.Date(), tr), units="days")
            ty
            ty <- data.frame(ty)
            ty
            #calculate account maintenance fees
            acc <- 60.0885 * ty
            acc

            #calculate amount of money to be deposited to utrade
            jjj <- mk$Amount
            jjj
            tmt <- jjj - acc
            tmt
            class(tmt)

            #converting numeric to string
            tb <- sprintf("%.0f", (tmt))
            tb

            Client <- x1$Client

            btk <- data.frame( Client, "Acc Fees" = acc)
            btk

            uhy <- data.frame(Client, "Amount" = tb, "Reason" = x1$Reason)
            uhy

            names(btk) <- gsub(x = names(btk),
                               pattern = "\\.",
                               replacement = " ")
            btk


            })

          output$marvin <- renderDataTable({
            gloria()

          })}

这是服务器端的许多代码。我认为ui方面无济于事。

1 个答案:

答案 0 :(得分:1)

您引用的mk无功值没有括号,这是必需的,因为从技术上讲,该对象是无功功能 。这应该可以解决您的问题:

jjj <- mk()$Amount