-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
138 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!-- | ||
This shortcode will include chunk returning WebR instance. | ||
Global shinylive configuration is available in the `_quarto.yaml` file. | ||
--> | ||
|
||
::: {.callout-warning appearance="simple"} | ||
## Experimental use! | ||
::: | ||
|
||
Modify the code below and run it to see the results. | ||
|
||
<!-- | ||
we have to put some code upfront | ||
- need to setup repos on r-universe - currently it's not possible to setup this elsewhere (e.g. shinylive config or chunk attribute) | ||
- currently shinylive is using [email protected] which is missing a feature of shimming `library()` calls - need to add this manually | ||
--> | ||
|
||
```{r shinylive-constructor, echo=FALSE, results='asis'} | ||
repo_url <- ifelse(identical(Sys.getenv("QUARTO_PROFILE"), "stable"), "https://insightsengineering.r-universe.dev", "https://pharmaverse.r-universe.dev") | ||
text <- unlist(c( | ||
"```{shinylive-r}", | ||
"#| standalone: true", | ||
"#| viewerHeight: 800", | ||
"#| components: [viewer, editor]", | ||
"#| layout: vertical", | ||
"", | ||
"# -- WEBR HELPERS --", | ||
sprintf("options(webr_pkg_repos = c(\"r-universe\" = \"%s\", getOption(\"webr_pkg_repos\")))", repo_url), | ||
"if (packageVersion(\"webr\") < \"0.3.0\") {", | ||
" .e <- as.environment(\"webr_shims\")", | ||
" .e[[\"library\"]] <- function(pkg, ...) {", | ||
" package <- as.character(substitute(pkg))", | ||
" if (length(find.package(package, quiet = TRUE)) == 0) {", | ||
" webr::install(package)", | ||
" }", | ||
" base::library(package, character.only = TRUE, ...)", | ||
" }", | ||
"}", | ||
"", | ||
"# -- APP CODE --", | ||
knitr::knit_code$get(c("teal")), | ||
"```" | ||
)) | ||
cat(text, sep = "\n") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!-- | ||
This shortcode will include chunk returning WebR instance. | ||
It requires pre-set `webr_code_labels` variable (character vector) containing labels of chunks to be included. | ||
Global WebR configuration is available in the `_quarto.yaml` file. | ||
--> | ||
|
||
::: {.callout-warning appearance="simple"} | ||
## Experimental use! | ||
::: | ||
|
||
Modify the code below and run it to see the results. Note that this includes also the "Data Setup" step from previous tab to make the code fully executable. | ||
|
||
```{r, echo=FALSE, results='asis'} | ||
if (!exists("webr_code_labels")) { | ||
webr_code_labels <- character(0L) | ||
} | ||
if (!all(webr_code_labels %in% knitr::all_labels())) { | ||
stop(sprintf( | ||
"Not all of provided labels exist in the current document!\nNot found labels are: %s.", | ||
paste0(setdiff(webr_code_labels, knitr::all_labels()), collapse = ", ") | ||
)) | ||
} | ||
text <- unlist(c( | ||
"```{webr-r}", | ||
"#| editor-max-height: 500", | ||
"#| autorun: true", | ||
lapply(webr_code_labels, knitr::knit_code$get), | ||
"```" | ||
)) | ||
cat(text, sep = "\n") | ||
``` |