I now have a few shiny apps (written as packages) that use 'meta-functions' that pipeline other functions and use shiny::withProgress
to update progress.
Example:
copyToNewDatabase <- function(existingDBPool,
newDBPool,
sampleIDs){
shiny::withProgress(message = 'Copying data to new database',
detail = 'Connecting experiments...',
value = 0, {
someFunction(...)
setProgress(value = 0.2,
message = 'Copying data to new database',
detail = 'Setting up new experiment...',
session = getDefaultReactiveDomain())
someFunction(...)
}
}
copyToNewDatabase()
However these meta-functions are un-testable outside of a shiny session and so to make that work we can change how that is written to something like:
copyToNewDatabase <- function(existingDBPool,
newDBPool,
sampleIDs){
someFunction(...)
if (!exists("session")) {
shiny::setProgress(value = 0.2,
message = 'Copying data to new database',
detail = 'Setting up new experiment...',
session = getDefaultReactiveDomain())
}
someFunction(...)
}
shiny::withProgress(message = 'Copying data to new database',
detail = 'Connecting experiments...',
value = 0, {
copyToNewDatabase()
}
Obviously testing whether session
exists is not a solution to this problem.
- Is there a better way for testing whether the function is being run inside a shiny session?
- Maybe there's some way to make these functions
withProgress
/setProgress
available for use outside of a shiny session (e.g. just throws warnings outside of a shiny session), so that the behavior can be better tested (eg with testthat).