1

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
  • 1
    If you remove the data<- from before the querydb.. statements does that help? Commented Apr 2, 2014 at 15:29

1 Answer 1

1

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) } 
Sign up to request clarification or add additional context in comments.

2 Comments

thanks this does the trick, still don't understand why db2 worked and bd1 not
By default R returns the last evaluated statement in an expression. So you don't technically need to call return at the end, you could just reference the variable data. Since db2 was the last evaluated block, it got returned if the conditional passed. db1's data was never the last evaluated statement, so it would never get returned.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.