1
votes

I'm making a shiny app that displays the datatable with the results of a database query. I use an in-house package for retrieving the data and I'm sure this works correctly.

When I want to display the datatable from one of the db's I have no problems, but when I want to display the other the table simply doesn't appear.

I use the reactive function to retrieve the data and renderDataTable() for displaying it. Here is the code:

shinyServer(function(input, output) {
    dataset <- reactive({
    if(input$experiment!=""&!is.null(input$experiment)){
      if(input$db=="db1"){
        data <- querydb1(experimentID=input$experiment)
      }
      if(input$db=="db2"){
        data <- querydb2(experimentID=input$experiment)
      }
    }
  })



  # output table
  output$data <- renderDataTable({
    dataset()
  })
})
1
If you remove the data<- from before the querydb.. statements does that help? - John Paul

1 Answers

1
votes

Your reactive needs to return something. Try this:

if(input$experiment!=""&!is.null(input$experiment)){
  if(input$db=="db1"){
    data <- querydb1(experimentID=input$experiment)
  }
  if(input$db=="db2"){
    data <- querydb2(experimentID=input$experiment)
  }
  return(data)
}