Data suppression within Shiny Dashboard

Viewed 47

I’m very new to using R let alone shiny dashboard but nevertheless I have a project that requires using it. What I am trying to accomplish is some way of suppressing a particular amount of results in an output. I currently have a dashboard in which I have several selectInputs that filter the results of a table. For instance a user could filter by a particular county, age group, and gender and would receive a table that contains all of those results. Let’s say a user did that and received less than 30 results, this is where I need the dashboard to respond with not supplying the results and maybe even a prompt to the user (I would settle for just the data suppression).

The database I am working with is extremely large and suppressing on that side would ultimately drop the overall data quality. My thought is that I would need something on the server side that basically says when filtered results are >30 to not display.

Please let me know if anymore clarification is needed and I apologize ahead of time for the lack of R knowledge.

Thanks!

1 Answers

In your server, you're generating an output table that's something like:

output$table <- renderDataTable({ df %>% filter(var1 == "input$var1" & 
                                                var2 == "input$var2") })

And you need to return an error message in the ui the event that nrow(output$table) < 30.

So I'd recommend utilizing ifelse in both your server and ui to handle each of these cases. Something like:

server

table_react <- reactive({ 
    temp <- df %>% filter(var1 == "input$var1" & 
                          var2 == "input$var2")
    ifelse(nrow(temp) >= 30, temp, NULL) })

output$table <- renderDataTable({ table_react() })

ui

ifelse(table_react() == NULL,
       textOutput("Your selections result in a table with < 30 entries. Please try again."),
       dataTableOutput("table"))
Related