Skip to content

Commit

Permalink
Split quarto extension API so that bundles are minimized. (#21)
Browse files Browse the repository at this point in the history
* Conditionally add `attribs` field to avoid many `NULL` values that will be removed

* Allow `head` in quarto dep to be passed through

* Allow dependencies to be split by `base`, `r`, and `python`

* Update quarto extension methods

* Update test-quarto_ext.R

* Stupid language server

* Document non-exported method quarto_ext()

* `devtools::document()` (GitHub Actions)

* Add support for `--version` to `quarto_ext()`

* Bump supported assets version

* Update assets.R

* Update shinylive.qmd

* Install dev versions of py-shinylive and shinylive assets

* Spelling / missing args

* Do not install pyshinylive assets. Instead, only copy from local folder

* Update R-CMD-check.yaml

* Update R-CMD-check.yaml

* Better update message

* Update readme. Reduce most of R package availability section. Remove 2/3 known limitations

* Make filter name consistent. Use consistent starting value for n

* Use published versions of shinylive assets and py-shinylive
  • Loading branch information
schloerke authored Oct 5, 2023
1 parent ec11991 commit 5f69de0
Show file tree
Hide file tree
Showing 11 changed files with 626 additions and 214 deletions.
24 changes: 11 additions & 13 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ jobs:
python-version: "3.11"

- name: Upgrade pip
shell: bash
run: |
python -m pip install --upgrade pip
- name: Install py-shinylive
shell: bash
run: |
pip install shinylive
- name: Install assets for py-shinylive
run: |
shinylive assets info
shinylive assets download
shinylive assets info
# pip install https://github.com/posit-dev/py-shinylive/archive/split_api.zip
- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
Expand All @@ -52,6 +50,8 @@ jobs:
run: |
cd local/quarto
quarto add quarto-ext/shinylive --no-prompt
# Trouble installing from branch. Using url instead.
# quarto add https://github.com/quarto-ext/shinylive/archive/v2_api.zip --no-prompt
- name: Install R, system dependencies, and package dependencies
uses: rstudio/shiny-workflows/setup-r-package@v1
Expand Down Expand Up @@ -80,7 +80,10 @@ jobs:
shell: Rscript {0}
run: |
shinylive_lua <- file.path(
"local", "quarto", "_extensions", "quarto-ext", "shinylive", "shinylive.lua"
"local", "quarto", "_extensions",
# (When installing from a zip url, there is no `quarto-ext` dir.)
"quarto-ext",
"shinylive", "shinylive.lua"
)
shinylive_lua |>
brio::read_file() |>
Expand All @@ -90,13 +93,8 @@ jobs:
fixed = TRUE
) |>
sub(
pattern = " local deps = quarto.json.decode(depJson)",
replacement = " print(depJson)\n local deps = quarto.json.decode(depJson)",
fixed = TRUE
) |>
sub(
pattern = " local appDeps = quarto.json.decode(appDepsJson)",
replacement = " print(appDepsJson)\n local appDeps = quarto.json.decode(appDepsJson)",
pattern = "-- print(\"res",
replacement = "-- print(\"res",
fixed = TRUE
) |>
brio::write_file(shinylive_lua)
Expand Down
47 changes: 21 additions & 26 deletions R/assets.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#' Manage shinylive assets
#'
#' Helper methods for managing shinylive assets.
Expand All @@ -15,13 +14,12 @@
#' behavior should be used.
#' @export
assets_download <- function(
version = assets_version(),
...,
# Note that this is the cache directory, which is the parent of the assets
# directory. The tarball will have the assets directory as the top-level subdir.
dir = assets_cache_dir(),
url = assets_bundle_url(version)
) {
version = assets_version(),
...,
# Note that this is the cache directory, which is the parent of the assets
# directory. The tarball will have the assets directory as the top-level subdir.
dir = assets_cache_dir(),
url = assets_bundle_url(version)) {
tmp_targz <- tempfile(paste0("shinylive-", gsub(".", "_", version, fixed = TRUE), "-"), fileext = ".tar.gz")

on.exit(
Expand Down Expand Up @@ -103,9 +101,10 @@ install_local_helper <- function(

if (version != assets_version()) {
message(
"Warning: You are installing a local copy of shinylive that is not the same as the version used by the shinylive R package.",
"Warning: You are installing a local copy of shinylive assets that is not the same as the version used by the shinylive R package.",
"\nWarning: Unexpected behavior may occur!",
"\n\nNew version: ", version
"\n\nNew assets version: ", version,
"\nSupported assets version: ", assets_version()
)
}
}
Expand Down Expand Up @@ -175,11 +174,10 @@ assets_install_link <- function(
#' If a local copy of shinylive is installed, its path will be returned.
#' @export
assets_ensure <- function(
version = assets_version(),
...,
dir = assets_cache_dir(),
url = assets_bundle_url(version)
) {
version = assets_version(),
...,
dir = assets_cache_dir(),
url = assets_bundle_url(version)) {
stopifnot(length(list(...)) == 0)
if (!fs::dir_exists(dir)) {
message("Creating assets cache directory ", dir)
Expand Down Expand Up @@ -212,9 +210,8 @@ assets_ensure <- function(
#' the one used by the current version of \pkg{shinylive}.
#' @export
assets_cleanup <- function(
...,
dir = assets_cache_dir()
) {
...,
dir = assets_cache_dir()) {
stopifnot(length(list(...)) == 0)
versions <- vapply(
assets_dirs(dir = dir),
Expand Down Expand Up @@ -254,10 +251,9 @@ assets_cleanup <- function(
#' @param versions The assets versions to remove.
#' @export
assets_remove <- function(
versions,
...,
dir = assets_cache_dir()
) {
versions,
...,
dir = assets_cache_dir()) {
stopifnot(length(list(...)) == 0)
stopifnot(length(versions) > 0 && is.character(versions))

Expand All @@ -277,9 +273,8 @@ assets_remove <- function(


assets_dirs <- function(
...,
dir = assets_cache_dir()
) {
...,
dir = assets_cache_dir()) {
stopifnot(length(list(...)) == 0)
if (!fs::dir_exists(dir)) {
return(character(0))
Expand Down Expand Up @@ -322,7 +317,7 @@ assets_info <- function() {

cat(
collapse(c(
paste0("shinylive R package version: ", utils::packageVersion("shinylive")),
paste0("shinylive R package version: ", SHINYLIVE_R_VERSION),
paste0("shinylive web assets version: ", assets_version()),
"",
"Local cached shinylive asset dir:",
Expand Down
Loading

0 comments on commit 5f69de0

Please sign in to comment.