0
votes

I have a shiny app I have two dataframes which create a third dataframe. I want various things to be performed by a user on this merged dataframe. As a result this third dataframe should be reactive. The dataframe is only populated once the 'Merge' button has been pressed

What I dont understand is how to create a reactive dataframe when it does not exist when the app starts up.

My code so far:

ui.R

fluidPage(tabsetPanel(type = "tabs",
 tabPanel("Merged Dataset", tableOutput("table2"),
           actionButton("Endomerge2",label = "Endomerge2"),
           DT::dataTableOutput("pathTable"),
           DT::dataTableOutput("endoTable"),
           DT::dataTableOutput("mergedTable")
  )
))

server.R

library(shiny)

RV <- reactiveValues(data = DataToMerge1)
RV2 <- reactiveValues(data = DataToMerge2)
RV3<-reactiveVal(0)



server <- function(input, output) {      
  output$endotable = DT::renderDT({
    RV$data
  })
  output$pathTable = DT::renderDT({
    RV2$data
  })
  output$mergedTable = DT::renderDT({
    RV3$data
  })



 #Button to merge the dataframes on

    observeEvent(input$Endomerge2,{
    RV3$data<-Endomerge2(RV$data,"AcolumnToMerge",RV2$data,"AcolumnToMerge")
  },ignoreInit = TRUE)

}

At the moment I get the error of type of closure is not subsettable but I suspect that is just hiding a bigger error. So how can I create a new dataframe and show it in a new datatable in Shiny?

1
You are using Endomerge2 as a function. Have you tried RV3$data <- merge(RV$data, RV2$data, by = "AcolumnToMerge")akrun
@akrun I have to use Endomerge2 for various reasons but it does return a dataframe so this shouldnt be the problemSebastian Zeki

1 Answers

1
votes

reactiveVal() creates a single reactive value, not a list, so you cannot add a list item named data. Try this:

RV <- reactiveValues(data = DataToMerge1)
RV2 <- reactiveValues(data = DataToMerge2)
RV3 <- reactiveValues(data = data.frame())



server <- function(input, output) {      
  output$endotable = DT::renderDT({
    RV$data
  })
  output$pathTable = DT::renderDT({
    RV2$data
  })
  output$mergedTable = DT::renderDT({
    RV3$data
  })



 #Button to merge the dataframes on

    observeEvent(input$Endomerge2,{
    RV3$data<-Endomerge2(RV$data,"AcolumnToMerge",RV2$data,"AcolumnToMerge")
  },ignoreInit = TRUE)

}