简体   繁体   中英

R Shiny: merge two reactive datasets and display in table with DT

I am trying to merge these two reactive datasets and join them to display a table. Any advice? Here is the code in server.R:

  dataset1 <- reactive({
    result <- custom_function_call(*params in here*)
  })
    dataset2 <- reactive({
    result <- custom_function_call_v2(*params in here*)
  })




    joined_dataset <- reactive({
     result<-merge(x = dataset1(), y = dataset2(), by = "UniqueID", all = TRUE)

      result<-
        result%>%
        mutate(*dyplr code to create new cols here*)

        return(result)
        })

  output$summaryTableName <- 
    DT::renderDataTable({
      res <- joined_dataset()


      return(res)

    }) 

Error message: Error in as.data.frame.default: cannot coerce class "c("datatables", "htmlwidget")" to a data.frame Stack trace (innermost first): 99: as.data.frame.default 98: as.data.frame 97: nrow 96: merge.data.frame 95: merge

通过查看您的错误信息cannot coerce class "c("datatables", "htmlwidget")我敢肯定,你不小心使用DT::datatable()中的数据集作为一个在问题中提到,该DT::datatable()不能与另一个data.frame合并,我认为可以通过从数据集函数中删除DT::datatable()来使代码正常工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM