R/shiny-render.R

Defines functions lcarsSweepOutput lcarsBoxOutput renderLcarsSweep renderLcarsBox

Documented in lcarsBoxOutput lcarsSweepOutput renderLcarsBox renderLcarsSweep

#' Create an LCARS outputs (server side)
#'
#' Server-side functions for creating dynamic \code{lcarBox} and
#' \code{lcarsSweep}.
#'
#' @param expr An expression that returns a Shiny tag object, HTML, or a list
#' of such objects.
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' is useful if you want to save an expression in a variable.
#'
#' @export
#' @name renderLcars
#'
#' @seealso \code{\link{lcarsOutput}} for the corresponding UI-side function.
#' @examples
#' ## Only run examples in interactive R sessions
#' if (interactive()) {
#'
#'   ui <- lcarsPage(
#'     lcarsBoxOutput("box"),
#'     lcarsSweepOutput("sweep")
#'   )
#'
#'   server <- function(input, output) {
#'     output$box <- renderLcarsBox({
#'       lcarsBox()
#'     })
#'     output$sweep <- renderLcarsSweep({
#'       lcarsSweep()
#'     })
#'   }
#'
#'   shinyApp(ui, server)
#' }
renderLcarsBox <- function(expr, env = parent.frame(), quoted = FALSE){
  f <- shiny::exprToFunction(expr, env, quoted)
  shiny::renderUI(f())
}

#' @export
#' @rdname renderLcars
renderLcarsSweep <- function(expr, env = parent.frame(), quoted = FALSE){
  f <- shiny::exprToFunction(expr, env, quoted)
  shiny::renderUI(f())
}

#' Create an LCARS output (client side)
#'
#' UI-side functions for creating dynamic \code{lcarBox} and \code{lcarsSweep}.
#'
#' @param outputId Output variable name.
#'
#' @export
#' @name lcarsOutput
#'
#' @seealso \code{\link{renderLcars}} for the corresponding server-side
#' function.
#' @examples
#' ## Only run examples in interactive R sessions
#' if (interactive()) {
#'
#'   ui <- lcarsPage(
#'     lcarsBoxOutput("box"),
#'     lcarsSweepOutput("sweep")
#'   )
#'
#'   server <- function(input, output) {
#'     output$box <- renderLcarsBox({
#'       lcarsBox()
#'     })
#'     output$sweep <- renderLcarsSweep({
#'       lcarsSweep()
#'     })
#'   }
#'
#'   shinyApp(ui, server)
#' }
lcarsBoxOutput <- function(outputId){
  shiny::uiOutput(outputId)
}

#' @export
#' @rdname lcarsOutput
lcarsSweepOutput <- function(outputId){
  shiny::uiOutput(outputId)
}

Try the lcars package in your browser

Any scripts or data that you put into this service are public.

lcars documentation built on Sept. 10, 2023, 9:07 a.m.