Shows the branch of the running app. If you hover over the branch, a popover shows the commit and the times at which the R process, the app and the session started.
Usage
show_deployment(tz = Sys.timezone())
show_deployment_details(tz = Sys.timezone())
get_deployment(tz = Sys.timezone(), app_started = Sys.time())
show_deployment_app(...)Arguments
- ...
Arguments passed on to
shiny::shinyApp().- tz
The time zone of the times. Defaults to the current time zone.
- app_started
A POSIXct time at which the app started.
Functions
show_deployment(): A label with abslib::popover(). Pass it to thetitleofbslib::page_navbar(), as inshow_deployment_app(). This needs Bootstrap 5.show_deployment_details(): The content of the popover, as an HTML description list, for any other UI.get_deployment(): A list of the full commitsha, theref,process_started,app_startedandsession_started.shaandrefareNAif unknown.show_deployment_app(): Example app.
Sources
The first of these provides sha and ref:
The variables of GitHub Actions (
GITHUB_SHA,GITHUB_HEAD_REF,GITHUB_REF_NAME) or GitLab CI/CD (CI_COMMIT_SHA,CI_MERGE_REQUEST_SOURCE_BRANCH_NAME,CI_COMMIT_REF_NAME). On pull requests and merged results pipelines, the commit is the merge commit that the job checked out, not the last commit of the branch.gitin the working directory, if the working tree is clean. Otherwise, the commit does not describe the running code. An app that runs from a clean tree of another repository shows the commit of that repository.The
DEPLOYMENT_SOURCEenvironment variable, an arbitrary string that is shown as theref.
Otherwise, both are NA.
Times
The times match when Shiny runs the code of an app, as explained in Scoping rules for Shiny apps and The server function:
process_started: When the R process started, as reported byproc.time(). In a long-running R session, this is earlier than the start of the app. Servers that run several processes for an app have one time for each.app_started: When you calledshow_deployment()orshow_deployment_details(). Call them in a staticui, outside of theserverfunction. Shiny runs that code once per R process: whenshiny::runApp()sourcesapp.R, before any user connects, or when you callshiny::shinyApp(). In a functionui, Shiny runs that code on each page load instead.get_deployment()uses the time of the call, unless you pass this time.session_started: When a user opened the app and the server rendered the page, just before Shiny calls theserverfunction for the new session.get_deployment()uses the time of the call, so call it in theserverfunction to get this time.
Use without crow
You can also copy these functions into your package, so that it does not depend on crow:
usethis::use_standalone("dataheld/crow", "show_deployment")