3

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!

Kamil Gosciminski
  • 16,547
  • 8
  • 49
  • 72

1 Answers1

0

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"))
Rich Pauloo
  • 7,734
  • 4
  • 37
  • 69
  • Is there anyway you can share the code within a shiny dashboard? I'm having trouble understanding how everything is working and where it should all go. I'm currently getting the error message "object 'output' not found". – Bushwick2019 Sep 12 '18 at 20:53
  • That error message seems unrelated to this problem, and indicates that you're requiring a variable `output` in a function that isn't defined elsewhere. Without seeing your actual code, or even better yet, a [minimum reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) it's really difficult to offer help. Can you try editing your question to include a reproducible example? – Rich Pauloo Sep 12 '18 at 21:31