-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nteetor
committed
Aug 21, 2019
0 parents
commit c8929d5
Showing
13 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
^.*\.Rproj$ | ||
^\.Rproj\.user$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData | ||
.Ruserdata | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Package: blaze | ||
Type: Package | ||
Title: Observe URIs and Routes with 'shiny' | ||
Version: 0.0.1 | ||
Author: c( | ||
person("Nathan", "Teetor", email = "[email protected]", role = c("aut", "cre"))) | ||
Maintainer: Nathan Teetor <[email protected]> | ||
Description: Simulate paging within a 'shiny' application by observering | ||
and reacting to URI changes. | ||
License: MIT | ||
Encoding: UTF-8 | ||
LazyData: true | ||
RoxygenNote: 6.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(getRoute) | ||
export(observeRoute) | ||
export(pushRoute) | ||
importFrom(shiny,getDefaultReactiveDomain) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#' @importFrom shiny getDefaultReactiveDomain | ||
NULL | ||
|
||
#' Route paths and URIs | ||
#' | ||
#' The `blaze` package makes simulating different routes within a shiny | ||
#' application possible. The approach makes use of the `#`, hash, portition of | ||
#' the uri to prevent the application from truly reloading. | ||
#' | ||
"_PACKAGE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#' Observe routes | ||
#' | ||
#' Observe a route path and run a handler expression. When the route specified | ||
#' by `path` is browsed to `handler` will be run. | ||
#' | ||
#' @param path A character string specifying a route path, by default `path` is | ||
#' treated as a regular expression, see `regex`. | ||
#' | ||
#' @param handler An expression or function to call when the uri matches `path`. | ||
#' | ||
#' @param env The parent environment of `handler`, defaults to the calling | ||
#' environment. | ||
#' | ||
#' @param quoted One of `TRUE` or `FALSE` specifying if `handler` is a quoted | ||
#' expression. If `TRUE`, the expression must be quoted with `quote()`. | ||
#' | ||
#' @param regex One of `TRUE` or `FALSE` specifying if `path` is treated as a | ||
#' regular expression, defaults to `TRUE`. | ||
#' | ||
#' @param domain A reactive context, defaults to | ||
#' `shiny::getDefaultReactiveDomain()`. | ||
#' | ||
#' @export | ||
observeRoute <- function(path, handler, env = parent.frame(), quoted = FALSE, | ||
regex = TRUE, | ||
domain = getDefaultReactiveDomain()) { | ||
h_expr <- shiny::exprToFunction(handler, env = env, quoted = quoted) | ||
|
||
o <- observe({ | ||
req(domain$clientData$url_hash) | ||
|
||
url <- sub("^#", "", domain$clientData$url_hash) | ||
|
||
is_match <- grepl(path, url, fixed = !regex) | ||
|
||
req(is_match) | ||
|
||
h_expr() | ||
}, domain = domain) | ||
|
||
invisible(o) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#' Route utilities | ||
#' | ||
#' Push a route or get the current application route. | ||
#' | ||
#' @param path A character string specifying a new route. | ||
#' | ||
#' @param session A reactive context, defaults to | ||
#' `shiny::getDefaultReactiveDomain()`. | ||
#' | ||
#' @export | ||
pushRoute <- function(path, session = getDefaultReactiveDomain()) { | ||
if (!grepl("^/", path)) { | ||
path <- paste0("/", path) | ||
} | ||
|
||
hash <- paste0("#", path) | ||
|
||
session$sendCustomMessage("blaze:push", list( | ||
hash = hash | ||
)) | ||
} | ||
|
||
#' @rdname pushRoute | ||
#' @export | ||
getRoute <- function(session = getDefaultReactiveDomain()) { | ||
hash <- shiny::isolate(session$clientData$url_hash) | ||
|
||
sub("^#", "", hash) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.onLoad <- function(pkg, lib) { | ||
shiny::addResourcePath("blaze", system.file("www", package = "blaze")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Version: 1.0 | ||
|
||
RestoreWorkspace: Default | ||
SaveWorkspace: Default | ||
AlwaysSaveHistory: Default | ||
|
||
EnableCodeIndexing: Yes | ||
UseSpacesForTab: Yes | ||
NumSpacesForTab: 2 | ||
Encoding: UTF-8 | ||
|
||
RnwWeave: Sweave | ||
LaTeX: pdfLaTeX | ||
|
||
AutoAppendNewline: Yes | ||
StripTrailingWhitespace: Yes | ||
|
||
BuildType: Package | ||
PackageUseDevtools: Yes | ||
PackageInstallArgs: --no-multiarch --with-keep.source | ||
PackageRoxygenize: rd,collate,namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
window.addEventListener("DOMContentLoaded", function(e) { | ||
Shiny.addCustomMessageHandler("blaze:push", function(msg) { | ||
if (msg.hash === undefined || msg.hash === null) { | ||
return; | ||
} | ||
|
||
window.history.pushState(null, null, msg.hash); | ||
window.dispatchEvent(new HashChangeEvent("hashchange")); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.