tag-examplesShinylive {roxy.shinylive}R Documentation

Custom ⁠@examplesShinylive⁠ tag.

Description

This function generates a new "Examples in Shinylive" section in the documentation. This section contains URL to the application in Shinylive and for HTML outputs: an iframe with the application. If no code is provided then the code is taken from the following ⁠@examples⁠ or ⁠@examplesIf⁠ tag.

Usage

#' @examplesShinylive${1:# example code (optional)}

Details

The application code must be executable inside Shinylive. If the application code includes functions from your package, you must add ⁠library(<package>)⁠ beforehand. For more information, refer to the Decoration section on how to use and decorate existing examples.

Note: All the packages used in the application code need to be installable in WebR. See this article for more details.

Decoration

To avoid repetition between the ⁠@examplesShinylive⁠ and ⁠@examples⁠ sections contents, there are special string literals to be used inside ⁠@examplesShinylive⁠ tag content that allow you to access the content(s) of the ⁠@examples⁠ or ⁠@examplesIf⁠ tags. These literals should be used as expressions embraced with {{ }}, which are then interpolated using glue::glue_data(..., .open = "{{", .close = "}}").

The following keywords are available:

This allows you to access and decorate existing example code to create executable application code for Shinylive. Refer to the examples section for possible use cases.

Examples

# As a part of documentation:

# basic example:
#' (docs)
#' @examplesShinylive
#' @examples
#' (example code)

# using keywords - `{{ next_example }}`:
#' (docs)
#' @examplesShinylive
#' foo <- 1
#' {{ next_example }}
#' bar <- 2
#' @examples
#' (example code)

# using keywords - `{{ prev_example }}`:
#' (docs)
#' bar <- 2
#' @examples
#' (example code)
#' @examplesShinylive
#' foo <- 1
#' {{ prev_example }}

# A typical example would be:
#' (docs)
#' @examplesShinylive
#' library(<package>)
#' interactive <- function() TRUE
#' {{ next_example }}
#' @examples
#' app <- ...
#' if (interactive()) {
#'   shinyApp(app$ui, app$server)
#' }

# multiple apps:
#' (docs)
#' @examplesShinylive
#' @examples
#' (example app 1)
#' @examplesShinylive
#' @examples
#' (example app 2)

# skip parts of example code:
#' (docs)
#' @examples
#' (example code - skipped)
#' @examplesShinylive
#' @examples
#' (example code - included)

# multiple apps with keywords:
#' (docs)
#' @examplesShinylive
#' x <- 1
#' {{ next_example }}
#' @examples
#' (example app 1)
#' @examplesShinylive
#' y <- 1
#' {{ next_example }}
#' @examples
#' (example app 2)

# combining multiple examples:
#' (docs)
#' @examples
#' (app pre-requisites)
#' @examples
#' (example app)
#' @examplesShinylive
#' {{ paste0(examples, collapse = ", ") }}

# identical to the above example but with a different approach:
#' (docs)
#' @examples
#' (app pre-requisites)
#' @examples
#' (example app)
#' @examplesShinylive
#' {{ paste0(lapply(tags_examples, `[[`, "raw"), collapse = ", ") }}

[Package roxy.shinylive version 1.0.0 Index]