zelda26
zelda26

Reputation: 489

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

Upvotes: 1

Views: 5199

Answers (1)

Shrek Tan
Shrek Tan

Reputation: 2863

By looking at your error message cannot coerce class "c("datatables", "htmlwidget"), I'm sure that you accidently use DT::datatable() in one of the datasets as mentioned in the question. The DT::datatable() is not something you can merge with another data.frame. I think you can get your codes work by removing the DT::datatable() from the dataset functions.

Upvotes: 2

Related Questions