From d87fa6af1050e79ec49a774ac90c48af55cac844 Mon Sep 17 00:00:00 2001 From: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Date: Tue, 30 Jul 2024 09:26:52 +0200 Subject: [PATCH] more enhanced remove large files; update to shinylive assets v0.5.0 --- .github/workflows/docs.yml | 42 ++++++++++++++++++- .../quarto-ext/shinylive/_extension.yml | 4 +- .../quarto-ext/shinylive/shinylive.lua | 12 +++++- book/_utils/shinylive.qmd | 17 +++----- 4 files changed, 58 insertions(+), 17 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 8914af4dd7..7469c38468 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -101,8 +101,24 @@ jobs: - name: Remove large WebR assets 🧹 run: | - find book/_site/site_libs/quarto-contrib/shinylive-*/shinylive/webr/packages/ -type f -size +100M -exec rm -f {} \; - shell: bash + packages_path <- sprintf("_site/site_libs/quarto-contrib/shinylive-%s/shinylive/webr/packages", shinylive::assets_version()) + + # remove the dirs with size > 100 MB + for (x in list.dirs(packages_path)) { + x_files <- file.info(list.files(x, full.names = TRUE)) + if (any(x_files$size > 100 * 1024^2)) { + print(x) + print(x_files) + unlink(x, recursive = TRUE) + } + } + + # refresh the `metadata.rds` file + metadata_path <- file.path(packages_path, "metadata.rds") + metadata <- readRDS(metadata_path) + new_metadata <- metadata[intersect(names(metadata), list.dirs(packages_path, full.names = FALSE))] + saveRDS(new_metadata, metadata_path) + shell: Rscript {0} - name: Publish docs 📔 uses: peaceiris/actions-gh-pages@v3 @@ -163,6 +179,28 @@ jobs: zip -r9 ../../site.zip * shell: bash working-directory: book/_site + + - name: Remove large WebR assets 🧹 + run: | + packages_path <- sprintf("_site/site_libs/quarto-contrib/shinylive-%s/shinylive/webr/packages", shinylive::assets_version()) + + # remove the dirs with size > 100 MB + for (x in list.dirs(packages_path)) { + x_files <- file.info(list.files(x, full.names = TRUE)) + if (any(x_files$size > 100 * 1024^2)) { + print(x) + print(x_files) + unlink(x, recursive = TRUE) + } + } + + # refresh the `metadata.rds` file + metadata_path <- file.path(packages_path, "metadata.rds") + metadata <- readRDS(metadata_path) + new_metadata <- metadata[intersect(names(metadata), list.dirs(packages_path, full.names = FALSE))] + saveRDS(new_metadata, metadata_path) + shell: Rscript {0} + - name: Upload docs ⬆ if: startsWith(github.ref, 'refs/tags/v') diff --git a/book/_extensions/quarto-ext/shinylive/_extension.yml b/book/_extensions/quarto-ext/shinylive/_extension.yml index 01b4d68b1d..6634416d3e 100644 --- a/book/_extensions/quarto-ext/shinylive/_extension.yml +++ b/book/_extensions/quarto-ext/shinylive/_extension.yml @@ -1,8 +1,8 @@ name: shinylive title: Embedded Shinylive applications author: Winston Chang -version: 0.1.0 -quarto-required: ">=1.2.198" +version: 0.2.0 +quarto-required: ">= 1.2.198" contributes: filters: - shinylive.lua diff --git a/book/_extensions/quarto-ext/shinylive/shinylive.lua b/book/_extensions/quarto-ext/shinylive/shinylive.lua index e2828db617..6890a7a31e 100644 --- a/book/_extensions/quarto-ext/shinylive/shinylive.lua +++ b/book/_extensions/quarto-ext/shinylive/shinylive.lua @@ -393,6 +393,16 @@ function getShinyliveBaseDeps(language) return deps end +-- Legacy quarto cli location +quarto_cli_path = "quarto" +if quarto.config ~= nil and quarto.config.cli_path ~= nil then + -- * 2024/05/03 - Christophe: + -- `quarto run` needs to be called using the same quarto CLI that called the extension. + -- This is done by using `quarto.config.cli_path()` from Quarto 1.5 Lua API. + -- https://github.com/quarto-dev/quarto-cli/pull/9576 + quarto_cli_path = quarto.config.cli_path() +end + return { { CodeBlock = function(el) @@ -415,7 +425,7 @@ return { -- Convert code block to JSON string in the same format as app.json. local parsedCodeblockJson = pandoc.pipe( - "quarto", + quarto_cli_path, { "run", codeblockScript, language }, el.text ) diff --git a/book/_utils/shinylive.qmd b/book/_utils/shinylive.qmd index cf05501d58..683216dfd7 100644 --- a/book/_utils/shinylive.qmd +++ b/book/_utils/shinylive.qmd @@ -16,34 +16,27 @@ The performance is slighly worse and some of the features (e.g. downloading) mig ```{r shinylive-constructor, echo = FALSE, results = "asis", opts.label = "skip_if_testing"} repo_url <- ifelse(identical(Sys.getenv("QUARTO_PROFILE"), "stable"), "https://insightsengineering.r-universe.dev", "https://pharmaverse.r-universe.dev") +options(webr_pkg_repos = c("r-universe" = repo_url, getOption("webr_pkg_repos"))) text <- unlist(c( + ":::{.column-screen-inset-right}", "```{shinylive-r}", "#| standalone: true", "#| viewerHeight: 800", + "#| editorHeight: 200", "#| 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") ```