I have a Shiny app that programmatically creates widgets from an sqlite3 databases and uses those widgets to filter data from that database. I can get the current values of these widgets like so:
problem_param_values <- function(experiments, prefix, input) {
params <- problem_params(experiments)
values <- lapply(params,
function(p)
eval(parse(text = sprintf("input$%s",
paste0(prefix, "problem_param", p)))))
names(values) <- params
return(values)
}
I am trying to create a filter from this, but I am having a hard time finding the right way to quote/unquote things. This is what I have so far:
problem_param_select <- function(param, val) {
# Use fuzzy matching when comparing numbers because precision is lost
# when real-valued parameter values are converted to strings for
# parameter selection widget.
expr(!!sprintf("abs(%s - %s) < 0.0000001", param, val))
}
...
param_values <- problem_param_values(experiments(), "perf", input)
filter_expr <- mapply(
problem_param_select, names(param_values), param_values)
data <- performance() %>% filter(!!!filter_expr)
This doesn't work. If I add this before the last statement I can see that the wrong SQL query is generated:
cat(performance() %>% filter(!!!filter_expr) %>% show_query())
Any suggestions on how to fix / debug this?