Skip to content

Commit

Permalink
Hack solution for resource paths
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Feb 23, 2021
1 parent 9e34701 commit 345371c
Show file tree
Hide file tree
Showing 17 changed files with 16 additions and 8 deletions.
10 changes: 5 additions & 5 deletions action-feedback.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ server <- function(input, output, session) {
```

```{r feedback, fig.cap = demo$caption("Using `feedbackWarning()` to display warning for invalid inputs. The app on the left shows a valid input, the app on the right shows an invalid (odd) input with warning message."), echo = FALSE, message = FALSE, out.width = "50%", }
demo <- demoApp$new("action-feedback/feedback", ui, server)
demo <- demoApp$new("action-feedback/feedback", ui, server, packages = "shinyFeedback", before = ~ shinyFeedback::useShinyFeedback())
demo$resize(width = 250)
demo$takeScreenshot("even")
demo$setInputs(n = 9)
Expand Down Expand Up @@ -276,7 +276,7 @@ server <- function(input, output, server) {
```

```{r validate, fig.cap = "If the inputs are valid, the output shows the transformation. If the combination of inputs is invalid, then the output is replaced with an informative message.", echo = FALSE, message = FALSE, out.width = "50%"}
demo <- demoApp$new("action-feedback/validate", ui, server)
demo <- demoApp$new("action-feedback/validate", ui, server, packages = "shinyFeedback", before = ~ shinyFeedback::useShinyFeedback())
demo$resize(300)
demo$takeScreenshot("init")
demo$setInputs(x = -1, trans = "log")
Expand Down Expand Up @@ -588,7 +588,7 @@ server <- function(input, output, session) {
```

```{r, echo = FALSE, message = FALSE}
demo <- demoApp$new("action-feedback/waiter", ui, server)
demo <- demoApp$new("action-feedback/waiter", ui, server, packages = "waiter", before = ~ waiter::use_waitress())
demo$deploy()
```

Expand Down Expand Up @@ -632,7 +632,7 @@ server <- function(input, output, session) {
```

```{r, echo = FALSE, message = FALSE}
demo <- demoApp$new("action-feedback/spinner-1", ui, server)
demo <- demoApp$new("action-feedback/spinner-1", ui, server, packages = "waiter", before = ~ waiter::use_waiter())
demo$deploy()
```

Expand Down Expand Up @@ -663,7 +663,7 @@ server <- function(input, output, session) {
```

```{r, echo = FALSE, message = FALSE}
demo <- demoApp$new("action-feedback/spinner-2", ui, server)
demo <- demoApp$new("action-feedback/spinner-2", ui, server, packages = "waiter", before = ~ waiter::use_waiter())
demo$deploy()
```

Expand Down
3 changes: 3 additions & 0 deletions demo-app.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ library(shiny)
attach(readRDS("data.rds"))

lapply(`_packages`, library, character.only = TRUE)
if (exists("_before")) {
`_before`()
}

if (!exists("_server")) {
`_server` <- function(input, output, session) {}
Expand Down
11 changes: 8 additions & 3 deletions demo.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ demoApp <- R6::R6Class("demoApp", public = list(
server = NULL,
data = NULL,
assets = NULL,
before = NULL,

running = FALSE,
driver = NULL,
Expand All @@ -26,12 +27,13 @@ demoApp <- R6::R6Class("demoApp", public = list(
packages = character(),
assets = NULL,
bookmark = NULL,
before = NULL,
env = parent.frame()
) {
self$name <- name
self$ui <- ui
self$server <- rlang::zap_srcref(server)
self$data <- app_data(server, ui, packages, bookmark, env)
self$data <- app_data(server, ui, packages, bookmark, env, before)
self$assets <- assets

fs::dir_create(fs::path("demos", fs::path_dir(name)))
Expand Down Expand Up @@ -257,15 +259,18 @@ demoApp <- R6::R6Class("demoApp", public = list(

# server + ui -> app ------------------------------------------------------

app_data <- function(server, ui, packages = character(), bookmark = NULL, env = parent.frame()) {
app_data <- function(server, ui, packages = character(), bookmark = NULL, env = parent.frame(), before = NULL) {
globals <- app_server_globals(server, env)

data <- globals$globals
data$`_ui` <- ui
data$`_server` <- server
data$`_resources` <- shiny::resourcePaths()
data$`_packages` <- union(globals$packages, packages)
data["_bookmark"] <- list(bookmark) # NULLs grrrrr
data$`_before` <- if (!is.null(before)) {
rlang::as_function(before, env = global_env())
}

data
}

Expand Down
Binary file modified demos/action-feedback/dialog.rds
Binary file not shown.
Binary file modified demos/action-feedback/feedback.rds
Binary file not shown.
Binary file modified demos/action-feedback/notification-transient.rds
Binary file not shown.
Binary file modified demos/action-feedback/notification-updates.rds
Binary file not shown.
Binary file modified demos/action-feedback/notify-persistent.rds
Binary file not shown.
Binary file modified demos/action-feedback/progress.rds
Binary file not shown.
Binary file modified demos/action-feedback/require-cancel.rds
Binary file not shown.
Binary file modified demos/action-feedback/require-simple.rds
Binary file not shown.
Binary file modified demos/action-feedback/require-simple2.rds
Binary file not shown.
Binary file modified demos/action-feedback/spinner-1.rds
Binary file not shown.
Binary file modified demos/action-feedback/spinner-2.rds
Binary file not shown.
Binary file modified demos/action-feedback/undo.rds
Binary file not shown.
Binary file modified demos/action-feedback/validate.rds
Binary file not shown.
Binary file modified demos/action-feedback/waiter.rds
Binary file not shown.

0 comments on commit 345371c

Please sign in to comment.