I would like to dynamically perform an SQL query (e.g. every day) and store the data into a reactive dataframe within a Shiny app. However, if the returned query contains NULL values or Zeros, I would like to retain the old values instead of it being replaced by the latest queried NULL or 0s.
For example:
Initial dataframe:
date a b c d
2019-01-01 1 2 3 4
2019-01-02 2 3 4 5
Returned query stored as a dataframe:
date a b c d
2019-01-03 NA 4 3 0
After SQL Query is returned and binded into the dataframe using dplyr bind_rows, the final dataframe should look like this:
date a b c d
2019-01-01 1 2 3 4
2019-01-02 2 3 4 5
2019-01-03 2 4 3 5 # 2 retained instead of NULL, 5 retained instead of 0
I understand that I probably have to write a conditional statement like the following pseudo code:
if (is.null(returned_query) & (returned_query != 0)) {
// some code to replace value with the most recent value
} else {
// proceed with bind_rows()
}
Unfortunately, I have no control over the SQL queries, and I have to do this in R. Anyone has a solution to this?