Skip to content

Commit d790796

Browse files
committed
add reactRouterExample()
1 parent 85bd0a6 commit d790796

4 files changed

Lines changed: 59 additions & 2 deletions

File tree

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export(Outlet)
1313
export(Route)
1414
export(Routes)
1515
export(reactRouterDependency)
16+
export(reactRouterExample)
1617
export(updateLink.shinyInput)
1718
export(updateNavLink.shinyInput)
1819
importFrom(shiny.react,JS)

R/reactRouterExample.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#' Run reactRouterExample example
2+
#'
3+
#' Launch a Shiny example app or list the available examples.
4+
#' Use `reactRouter::reactRouterExample("basic")` to run a showcase app.
5+
#'
6+
#' @param example The name of the example to run, or `NULL` to retrieve the list of examples.
7+
#' @param ... Additional arguments to pass to `shiny::runApp()`.
8+
#' @return This function normally does not return;
9+
#' interrupt R to stop the application (usually by pressing Ctrl+C or Esc).
10+
#'
11+
#' @seealso [shiny.blueprint::runExample()] which this function is an adaptation.
12+
#'
13+
#' @export
14+
reactRouterExample <- function(example = NULL, ...) {
15+
examples <- system.file("examples", package = utils::packageName(), mustWork = TRUE)
16+
if (is.null(example)) {
17+
sub("\\.R$", "", list.files(examples))
18+
} else {
19+
path <- file.path(examples, example)
20+
if (!grepl("\\.R$", path) && !file.exists(path)) {
21+
path <- paste0(path, ".R")
22+
}
23+
shiny::runApp(path, ...)
24+
}
25+
}

README.Rmd

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,20 @@ HashRouter(
4040

4141
### Install
4242

43-
``` r
43+
```r
4444
#remotes::install_github("lgnbhl/reactRouter") # development version
4545

4646
install.packages("reactRouter")
4747
```
4848

49-
### More tutorials
49+
### Example
50+
51+
Get started with a showcase example:
52+
53+
```{r}
54+
# print all examples available: reactRouterExample()
55+
reactRouterExample("basic")
56+
```
5057

5158
Read the vignette [here](https://felixluginbuhl.com/reactRouter/articles/introduction.html) for detailed use cases with Quarto and R Shiny.
5259

man/reactRouterExample.Rd

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)