diff --git a/R/app.R b/R/app.R index a7b19d55..5c8b6a75 100644 --- a/R/app.R +++ b/R/app.R @@ -77,7 +77,8 @@ with_head_tags <- function(ui) { #' Rhino application #' #' The entrypoint for a Rhino application. -#' Your `app.R` should contain nothing but a call to `rhino::app()`. +#' Your `app.R` should contain nothing but a call to `rhino::app()`, +#' and the app should be started with `shiny::runApp()`. #' #' This function is a wrapper around `shiny::shinyApp()`. #' It reads `rhino.yml` and performs some configuration steps (logger, static files, box modules). @@ -87,6 +88,10 @@ with_head_tags <- function(ui) { #' It should export two functions which take a single `id` argument - #' the `ui` and `server` of your top-level Shiny module. #' +#' Using `rhino::app()` directly is discouraged. +#' Being a wrapper around `shiny::shinyApp()`, +#' it does not allow features such as shiny.autoreload to work. +#' #' # Legacy entrypoint #' #' It is possible to specify a different way to load your application @@ -110,6 +115,9 @@ with_head_tags <- function(ui) { #' into a [Shiny module](https://shiny.rstudio.com/articles/modules.html) #' (functions taking a single `id` argument). #' +#' @param warn_on_direct_call `TRUE` by default. Set to `FALSE` to squelch warning when calling +#' `rhino::app()` directly. +#' #' @return An object representing the app (can be passed to `shiny::runApp()`). #' #' @examples @@ -118,7 +126,19 @@ with_head_tags <- function(ui) { #' rhino::app() #' } #' @export -app <- function() { +app <- function(warn_on_direct_call = TRUE) { + is_direct_call <- identical(parent.frame(), .GlobalEnv) + if (isTRUE(warn_on_direct_call) && isTRUE(is_direct_call)) { + cli::cli_warn( + c( + "!" = paste( + "{.code rhino::app()} shouldn't be used directly.", + "Please use {.code shiny::runApp()} instead." + ), + "i" = "To squelch this warning set {.code warn_on_direct_call = TRUE}." + ) + ) + } setup_box_path() box::purge_cache() configure_logger() diff --git a/man/app.Rd b/man/app.Rd index 6bac8a3f..ffc2b46d 100644 --- a/man/app.Rd +++ b/man/app.Rd @@ -4,14 +4,19 @@ \alias{app} \title{Rhino application} \usage{ -app() +app(warn_on_direct_call = TRUE) +} +\arguments{ +\item{warn_on_direct_call}{\code{TRUE} by default. Set to \code{FALSE} to squelch warning when calling +\code{rhino::app()} directly.} } \value{ An object representing the app (can be passed to \code{shiny::runApp()}). } \description{ The entrypoint for a Rhino application. -Your \code{app.R} should contain nothing but a call to \code{rhino::app()}. +Your \code{app.R} should contain nothing but a call to \code{rhino::app()}, +and the app should be started with \code{shiny::runApp()}. } \details{ This function is a wrapper around \code{shiny::shinyApp()}. @@ -21,6 +26,10 @@ You can run a Rhino application in typical fashion using \code{shiny::runApp()}. Rhino will load the \code{app/main.R} file as a box module (\code{box::use(app/main)}). It should export two functions which take a single \code{id} argument - the \code{ui} and \code{server} of your top-level Shiny module. + +Using \code{rhino::app()} directly is discouraged. +Being a wrapper around \code{shiny::shinyApp()}, +it does not allow features such as shiny.autoreload to work. } \section{Legacy entrypoint}{ It is possible to specify a different way to load your application