Title: | A Roxygen2 Extension for Shinylive |
---|---|
Description: | An extension for roxygen2 that allows to auto-create links to shinylive from examples in the documentation. |
Authors: | Pawel Rucki [aut, cre], F. Hoffmann-La Roche AG [cph, fnd] |
Maintainer: | Pawel Rucki <[email protected]> |
License: | Apache License 2.0 | file LICENSE |
Version: | 0.0.0.9010 |
Built: | 2024-10-25 14:16:07 UTC |
Source: | https://github.com/insightsengineering/roxy.shinylive |
Creates Shinylive url based on app code.
create_shinylive_url(code, mode = c("app", "editor"), header = TRUE)
create_shinylive_url(code, mode = c("app", "editor"), header = TRUE)
code |
( |
mode |
( |
header |
( |
(character(1)
) Shinylive app url.
code <- "this is your app code as a string" create_shinylive_url(code) create_shinylive_url(code, header = FALSE) create_shinylive_url(code, mode = "editor")
code <- "this is your app code as a string" create_shinylive_url(code) create_shinylive_url(code, header = FALSE) create_shinylive_url(code, mode = "editor")
@examplesShinylive
tag.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.
#' @examplesShinylive${1:# example code (optional)}
#' @examplesShinylive${1:# example code (optional)}
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.
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:
"{{ next_example }}"
- (the default if empty) "raw" element of the next example
"{{ prev_example }}"
- "raw" element of the previous example
"{{ tags_examples }}"
- a list of @examples
or @examplesIf
tags
"{{ examples }}"
- a list of "raw" elements from tags_examples
list elements
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.
# 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 = ", ") }}
# 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 = ", ") }}