restore_analysis {shinymgr}R Documentation

Re-store a previously executed shinymgr analysis by regenerating an R project from an renv lockfile

Description

Re-run an previously executed shinymgr analysis given an RDS file input from a previously saved analysis.

Usage

restore_analysis(analysis_path)

Arguments

analysis_path

File path to the RDS file that stores a previously executed analysis.

Details

The function accepts a single argument that defines the file path to a saved shinymgr analysis (RDS file). This function will find the lockfile and use it to create a new renv-enabled R project (a folder), that includes the full R library used by the developer when creating the app. The function creates this new project, copies the original RDS file to it, and copies a script that the user can run in an attempt to restore an old shinymgr analysis utilizing the R version and all package versions that the developer used when creating the app.

Value

No return value, restores an R environment from a saved analysis

More Info

The restore_analysis() function is described in the "analyses" tutorial.

Tutorials

The shinymgr learnr tutorials include, in order.

  1. learnr::run_tutorial(name = "intro", package = "shinymgr")

  2. learnr::run_tutorial(name = "shiny", package = "shinymgr")

  3. learnr::run_tutorial(name = "modules", package = "shinymgr")

  4. learnr::run_tutorial(name = "app_modules", package = "shinymgr")

  5. learnr::run_tutorial(name = "tests", package = "shinymgr")

  6. learnr::run_tutorial(name = "shinymgr", package = "shinymgr")

  7. learnr::run_tutorial(name = "database", package = "shinymgr")

  8. learnr::run_tutorial(name = "shinymgr_modules", package = "shinymgr")

  9. learnr::run_tutorial(name = "apps", package = "shinymgr")

  10. learnr::run_tutorial(name = "analyses", package = "shinymgr")

  11. learnr::run_tutorial(name = "reports", package = "shinymgr")

  12. learnr::run_tutorial(name = "deployment", package = "shinymgr")

References

https://code.usgs.gov/vtcfwru/shinymgr

See Also

Other analysis: rerun_analysis()

Examples

## Only run this example in interactive R sessions
if (interactive()) {

# -----------------------------------------------------------------
# Load the sample analysis from the shinymgr package and restore it. 
# -----------------------------------------------------------------

  # Get the path for the sample analysis from shinymgr
  analysis_path <- paste0(
    find.package('shinymgr'), 
    '/shinymgr/analyses/iris_explorer_Gandalf_2023_06_05_16_30.RDS'
  )
  
  # confirm file exists
  file.exists(analysis_path)

  dir_current <- getwd()

  # Re-run the sample analysis
  restore_analysis(analysis_path)
  
  # A new project will created in the temporary directory that
  # includes a script to run within the new renv project
  # Rerun the saved analysis from the restored environment:
  rerun_analysis('renv_iris_explorer_Gandalf_2023_06_05_16_30.RDS')
  
  # Reset directory and clean-up
  setwd(dir_current)
  unlink(
    file.path(tempdir(), paste0('renv_', basename(analysis_path))), 
    recursive = TRUE
  )
}

[Package shinymgr version 1.1.0 Index]