Skip to content

Commit

Permalink
v0.1.0 (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke authored Oct 11, 2023
1 parent 5f69de0 commit e5e62dc
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 35 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
^shinylive_assets$
^cran-comments\.md$
^revdep$
^CRAN-SUBMISSION$
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: shinylive
Title: Run Shiny applications in the browser
Title: Run 'shiny' Applications in the Browser
Version: 0.1.0
Authors@R:
c(
Expand All @@ -9,7 +9,7 @@ Authors@R:
person("George", "Stagg", role = "ctb", email = "george.stagg@posit.co"),
person("Posit Software, PBC", role = c("cph", "fnd"))
)
Description: Run Shiny applications in the browser using 'webR' package.
Description: Exporting 'shiny' applications with 'shinylive' allows you to run them entirely in a web browser, without the need for a separate R server. The traditional way of deploying 'shiny' applications involves in a separate server and client: the server runs R and 'shiny', and clients connect via the web browser. When an application is deployed with 'shinylive', R and 'shiny' run in the web browser (via 'webR'): the browser is effectively both the client and server for the application. This allows for your 'shiny' application exported by 'shinylive' to be hosted by a static web server.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Expand All @@ -26,6 +26,7 @@ Imports:
rlang,
tools
Suggests:
plumber,
httr,
spelling,
testthat (>= 3.0.0)
Expand Down
15 changes: 14 additions & 1 deletion R/assets.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#' @param url The URL to download the assets from. Unless testing, the default
#' behavior should be used.
#' @export
#' @return
#' `assets_version()` returns the version of the currently supported Shinylive.
#'
#' All other methods return `invisible()`.
assets_download <- function(
version = assets_version(),
...,
Expand All @@ -37,6 +41,8 @@ assets_download <- function(
message("Unzipping to ", dir, "/")
fs::dir_create(dir)
archive::archive_extract(tmp_targz, dir)

invisible()
}


Expand Down Expand Up @@ -122,6 +128,7 @@ install_local_helper <- function(
#' @param version The version of the assets being installed.
#' @inheritParams assets_download
#' @seealso [`assets_download()`], [`assets_ensure()`], [`assets_cleanup()`]
#' @return All method return `invisible()`.
#' @export
assets_install_copy <- function(
assets_repo_dir,
Expand All @@ -138,6 +145,8 @@ assets_install_copy <- function(
dir = dir,
version = version
)

invisible()
}

#' @describeIn install Creates a symlink of the local shinylive assets to the
Expand Down Expand Up @@ -165,6 +174,8 @@ assets_install_link <- function(
dir = dir,
version = version
)

invisible()
}


Expand All @@ -190,7 +201,7 @@ assets_ensure <- function(
assets_download(url = url, version = version, dir = dir)
}

assets_path
invisible(assets_path)
}


Expand Down Expand Up @@ -333,6 +344,8 @@ assets_info <- function() {
)),
sep = ""
)

invisible()
}


Expand Down
22 changes: 12 additions & 10 deletions R/export.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Export a Shiny app to a directory
#'
#' This function exports a Shiny app to a directory, which can then be served
#' using `httpuv::runStaticServer()`.
#' using `plumber`.
#'
#' @param appdir Directory containing the application.
#' @param destdir Destination directory.
Expand All @@ -10,28 +10,29 @@
#' interactively.
#' @param ... Ignored
#' @export
#' @return Nothing. The app is exported to `destdir`. Instructions for serving
#' the directory are printed to stdout.
#' @importFrom rlang is_interactive
#' @examples
#' \dontrun{
#' @examplesIf interactive()
#' app_dir <- system.file("examples", "01_hello", package = "shiny")
#' out_dir <- tempfile("shinylive-export")
#'
#' # Export the app to a directory
#' export(app_dir, out_dir)
#' #> Run the following in an R session to serve the app:
#' #> httpuv::runStaticServer(<OUT_DIR>)
#'
#' # Serve the exported directory
#' httpuv::runStaticServer(out_dir)
#' if (require(plumber)) {
#' library(plumber)
#' pr() %>%
#' pr_static("/", out_dir) %>%
#' pr_run()
#' }
export <- function(
appdir,
destdir,
...,
subdir = "",
verbose = is_interactive()
# full_shinylive = FALSE
) {
verbose = is_interactive()) {
verbose_print <- if (verbose) message else list

stopifnot(fs::is_dir(appdir))
Expand Down Expand Up @@ -154,7 +155,8 @@ export <- function(

verbose_print(
"\nRun the following in an R session to serve the app:\n",
" httpuv::runStaticServer(\"", destdir, "\")\n"
" library(plumber)\n",
" pr() %>% pr_static(\"/\", \"", destdir, "\") %>% pr_run()\n"
)

invisible()
Expand Down
5 changes: 1 addition & 4 deletions R/quarto_ext.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#' TODO-barret; update docs in py-shinylive


#' Quarto extension for shinylive
#'
#' Integration with https://github.com/quarto-ext/shinylive
#'
#' @param args Command line arguments passed by the extension. See details for more information.
#' @param ... Ignored.
#' @param pretty Whether to pretty print the JSON output.
#' @returns Nothing. Values are printed to stdout.
#' @return Nothing. Values are printed to stdout.
#' @section Command arguments:
#'
#' The first argument must be `"extension"`. This is done to match
Expand Down
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ Twin shinylive python package: https://github.com/posit-dev/py-shinylive

## Installation

You can install the released version of shinylive from CRAN via:

``` r
install.packages("shinylive")
```

You can install the development version of shinylive from GitHub via:

``` r
Expand All @@ -40,13 +46,13 @@ Once you have a Shiny application in `myapp/` and would like turn it into a Shin
shinylive::export("myapp", "site")
```

Then you can preview the application by running a web server and visiting it in a browser (this example is using the development version of `{httpuv}`):
Then you can preview the application by running a web server and visiting it in a browser:

``` r
## Get development version of `{httpuv}`
# install.packages("pak")
# pak::pak("rstudio/httpuv")
httpuv::runStaticServer("site/")
library(plumber)
pr() %>%
pr_static("/", "site/") %>%
pr_run()
```

At this point, you can deploy the `site/` directory to any static web hosting service.
Expand Down Expand Up @@ -185,13 +191,13 @@ shinylive_lua |>
Export a local app to a directory and run it:

```r
library(plumber)
pkgload::load_all()

# Delete prior
unlink("local/shiny-apps-out/")
unlink("local/shiny-apps-out/", recursive = TRUE)
export("local/shiny-apps/simple-r", "local/shiny-apps-out")
#> Run the following in an R session to serve the app:
#> httpuv::runStaticServer("local/shiny-apps-out")

# Host the local directory
httpuv::runStaticServer("local/shiny-apps-out")
pr() %>% pr_static("/", "local/shiny-apps-out") %>% pr_run()
```
64 changes: 62 additions & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,61 @@
## 2023-09-12
## Comments

#### 2023-10-10

Updates:
* Package description length and wording.
* Added single quotes around `'shiny'`
* Added return value for `assets.Rd` and `install.Rd`
* Updated `export.Rd` example to use `if(interactive())`
* The `export.Rd` example writes to a temp folder, the tests are only run on CI, and there are no vignettes. Only temp files are created.

Thank you,
Barret


#### 2023-10-09

Thanks,

Please do not start the description with "This package", package name,
title or similar.

The Description field is intended to be a (one paragraph) description of
what the package does and why it may be useful. Please add more details
about the package functionality and implemented methods in your
Description text.

Please always write package names, software names and API (application
programming interface) names in single quotes in title and description.
e.g: --> 'shiny'
Please note that package names are case sensitive.

Please add \value to .Rd files regarding exported methods and explain
the functions results in the documentation. Please write about the
structure of the output (class) and also what the output means. (If a
function does not return a value, please document that too, e.g.
\value{No return value, called for side effects} or similar)
Missing Rd-tags:
install.Rd: \value

Functions which are supposed to only run interactively (e.g. shiny)
should be wrapped in if(interactive()). Please replace /dontrun{} with
if(interactive()){} if possible, then users can see that the functions
are not intended for use in scripts / functions that are supposed to run
non interactively.

Please ensure that your functions do not write by default or in your
examples/vignettes/tests in the user's home filespace (including the
package directory and getwd()). This is not allowed by CRAN policies.
Please omit any default path in writing functions. In your
examples/vignettes/tests you can write to tempdir().

Please fix and resubmit.

Best,
Benjamin Altmann

#### 2023-10-06

This is a new package.

Expand All @@ -12,4 +69,7 @@ Barret

0 errors | 0 warnings | 1 note

* This is a new release.
* checking CRAN incoming feasibility ... NOTE
Maintainer: 'Barret Schloerke <barret@posit.co>'

New submission
5 changes: 5 additions & 0 deletions man/assets.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions man/export.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/install.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/quarto_ext.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e5e62dc

Please sign in to comment.