Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more enhanced remove large files; update to shinylive assets v0.5.0 #260

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions book/_extensions/quarto-ext/shinylive/_extension.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 11 additions & 1 deletion book/_extensions/quarto-ext/shinylive/shinylive.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
)
Expand Down
17 changes: 5 additions & 12 deletions book/_utils/shinylive.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,27 @@ The performance is slighly worse and some of the features (e.g. downloading) mig
<!--
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", 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")
```
Loading