Isolating database query

There are any number of ways to query external database and assign the results to a data frame object locally. Take a look, for example, at dblyr. To relieve the user of a cheatsheet on the three filters, shiny would be a good adjunct.

Here's some p_code

local_result <- dbplyr::{appropriate query}
revised_local <- local_result %>% {filter, select, mutate, summarise, etc.)

Without some proxy data (see reproducible example, called a reprex), I can't help with debugging. Overall there's nothing wrong to the eye with your code, it's simply not idiomatic and imports procedural/imperative constructs to an environment that is fundamentally functional. If you think of it as f(x) = fetch_query and g(x) modify_results in place, it goes much more smoothly.