Skip to content

Commit b80aa15

Browse files
Merge pull request #32 from simon-smart88/dev
Merge 0.4.0
2 parents 6abf008 + eb0059d commit b80aa15

40 files changed

+590
-618
lines changed

DESCRIPTION

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: shinyscholar
2-
Version: 0.3.0
2+
Version: 0.4.0
33
Title: A Template for Creating Reproducible 'shiny' Applications
44
Description: Create a skeleton 'shiny' application with create_template() that is
55
reproducible, can be saved and meets academic standards for attribution.
@@ -36,6 +36,7 @@ Authors@R:
3636
person("Robert", "Muscarella", email = "bob.muscarella@gmail.com", role = "ctb"))
3737
Depends:
3838
R (>= 3.5.0),
39+
bslib,
3940
gargoyle,
4041
leaflet (>= 2.0.2),
4142
shiny (>= 1.8.1)
@@ -48,15 +49,13 @@ Imports:
4849
tools,
4950
zip
5051
Suggests:
51-
bslib,
5252
DT (>= 0.5),
5353
dplyr (>= 1.0.2),
54-
future,
5554
httr2,
5655
knitcitations,
5756
leaflet.extras (>= 1.0.0),
5857
markdown,
59-
promises,
58+
mirai,
6059
R6,
6160
RColorBrewer,
6261
renv,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export(show_results)
2424
export(show_table)
2525
export(spurious)
2626
export(writeLog)
27+
import(bslib)
2728
import(gargoyle)
2829
import(leaflet)
2930
import(shiny)

NEWS.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,16 @@ shinyscholar 0.3.0
9595
- Switched to use `shinyWidgets::radioGroupButtons()` for module selection menu
9696
- Added a description of the package structure to the README
9797

98+
shinyscholar 0.4.0
99+
=============
100+
101+
### Bug fixes
102+
- Fixed UI generation in `create_template()`
103+
- Enter key no longer reruns a module when an error message is displayed
104+
- Fixed API calls in `select_query()` and `select_async()`
105+
106+
### Changes
107+
- Stopped running {shinytest2} tests on CRAN
108+
- Migrated from {promises} to {mirai} for running async tasks
109+
- Migrated to {bslib} layout functions and various UI tweaks
110+
- Added a small footer linking to the CRAN package to generated apps

R/create_template.R

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ tidy_purl <- function(params){
3636
#' \item `map` logical. Whether or not the module interacts with the map
3737
#' \item `result` logical. Whether or not the module produces results
3838
#' \item `rmd` logical. Whether or not the module is included in the markdown
39-
#' \item `save` logical. Whether or not the input values of the model should be saved
40-
#' \item `download` logical. Whether or not the input values of the model should be saved
39+
#' \item `save` logical. Whether or not the input values of the module should be saved
40+
#' \item `download` logical. Whether or not the module should include a downloadHandler
4141
#' \item `async` logical. Whether or not the module will run asynchronously
4242
#' }
4343
#' @param author character. Name of the author(s)
@@ -217,8 +217,7 @@ create_template <- function(path, name, common_objects, modules, author,
217217
if (async){
218218
import_line <- grep("*Imports*", description_lines)
219219
description_lines <- append(description_lines, " bslib,", import_line)
220-
description_lines <- append(description_lines, " future,", import_line + 2)
221-
description_lines <- append(description_lines, " promises,", import_line + 7)
220+
description_lines <- append(description_lines, " mirai,", import_line + 7)
222221
}
223222

224223
if (include_map){
@@ -233,6 +232,21 @@ create_template <- function(path, name, common_objects, modules, author,
233232

234233
writeLines(description_lines, file.path(path, "DESCRIPTION"))
235234

235+
# Package info ====
236+
237+
package_params <- c(
238+
file = system.file("app_skeleton", "package.Rmd", package = "shinyscholar"),
239+
list(name = name)
240+
)
241+
242+
package_lines <- tidy_purl(package_params)
243+
244+
if (!include_map){
245+
package_lines <- gsub("leaflet ", "", package_lines)
246+
}
247+
248+
writeLines(package_lines, file.path(path, "R", paste0(name,"-package.R")))
249+
236250
# Create common list ====
237251
# add always present objects to common
238252
common_objects_internal <- c(common_objects, c("meta", "logger", "state"))
@@ -306,23 +320,9 @@ create_template <- function(path, name, common_objects, modules, author,
306320

307321
component_interface_target <- grep("*Rmd/text_intro_tab.Rmd*", ui_lines) + 1
308322
for (i in 1:nrow(components)){
309-
ui_lines <- append(ui_lines, c(glue::glue(' # {toupper(components$long_component[i])} ####'),
310-
' conditionalPanel(',
311-
glue::glue(' "input.tabs == \'{components$component[i]}\'",'),
312-
glue::glue(' div("Component: {components$long_component[i]}", class = "componentName"),'),
313-
glue::glue(' help_comp_ui("{components$component[i]}Help"),'),
314-
' shinyWidgets::radioGroupButtons(',
315-
glue::glue(' "{components$component[i]}Sel", "Modules Available:",'),
316-
glue::glue(' choices = insert_modules_options("{components$component[i]}"),'),
317-
' direction = "vertical",',
318-
' status = "outline-secondary",',
319-
' width = "100%"',
320-
' ),',
321-
' tags$hr(),',
322-
glue::glue(' insert_modules_ui("{components$component[i]}")'),
323-
' ),'),
324-
component_interface_target)
325-
component_interface_target <- component_interface_target + 13
323+
comp_ui <- glue::glue(' insert_modules_ui("{components$component[i]}", "{components$long_component[i]}"),')
324+
ui_lines <- append(ui_lines, comp_ui, component_interface_target)
325+
component_interface_target <- component_interface_target + 1
326326
}
327327
writeLines(ui_lines, file.path(path, "inst", "shiny", "ui.R"))
328328

@@ -504,7 +504,7 @@ create_template <- function(path, name, common_objects, modules, author,
504504
file.copy(www_files, file.path(path, "inst", "shiny"), recursive = TRUE)
505505

506506
# copy helpers ====
507-
helper_file <- system.file("shiny", "helpers.R", package = "shinyscholar")
507+
helper_file <- system.file("shiny", "ui_helpers.R", package = "shinyscholar")
508508
file.copy(helper_file, file.path(path, "inst", "shiny"))
509509

510510
helper_function_params <- c(

R/helper_functions.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ spurious <- function(x) {
4646
bslib::accordion(x)
4747
DT::renderDataTable(x)
4848
dplyr::add_count(x)
49-
future::as.cluster(x)
5049
httr2::curl_help(x)
5150
leaflet.extras::removeDrawToolbar(x)
51+
mirai::mirai(x)
5252
markdown::html_format(x)
53-
promises::as.promise(x)
5453
R6::R6Class(x)
5554
RColorBrewer::brewer.pal(x)
5655
rintrojs::introjs(x)

R/select_async_f.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ select_async <- function(poly, date, token, async = FALSE) {
5656

5757
bbox <- c(min(poly[,1]), max(poly[,2]), max(poly[,1]), min(poly[,2]))
5858

59-
search_url <- glue::glue("https://ladsweb.modaps.eosdis.nasa.gov/api/v2/content/archives?products=MCD15A2H&temporalRanges={date}&regions=[BBOX]W{bbox[1]}%20N{bbox[2]}%20E{bbox[3]}%20S{bbox[4]}")
59+
search_url <- glue::glue("https://ladsweb.modaps.eosdis.nasa.gov/api/v2/content/archives?products=MCD15A2H&temporalRanges={date}&regions=[BBOX]W{bbox[1]}%20N{bbox[2]}%20E{bbox[3]}%20S{bbox[4]}&archiveSets=61")
6060
check <- check_url(search_url)
6161

6262
if (!is.null(check)){

R/select_query_f.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ select_query <- function(poly, date, token, logger = NULL) {
9393

9494
bbox <- c(min(poly[,1]), max(poly[,2]), max(poly[,1]), min(poly[,2]))
9595

96-
search_url <- glue::glue("https://ladsweb.modaps.eosdis.nasa.gov/api/v2/content/archives?products=MCD15A2H&temporalRanges={date}&regions=[BBOX]W{bbox[1]}%20N{bbox[2]}%20E{bbox[3]}%20S{bbox[4]}")
96+
search_url <- glue::glue("https://ladsweb.modaps.eosdis.nasa.gov/api/v2/content/archives?products=MCD15A2H&temporalRanges={date}&regions=[BBOX]W{bbox[1]}%20N{bbox[2]}%20E{bbox[3]}%20S{bbox[4]}&archiveSets=61")
9797
check <- check_url(search_url)
9898

9999
if (!is.null(check)){

R/shinyscholar-package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
#' function \code{\link{run_shinyscholar}} and requires
1515
#' \code{install.packages("shinyscholar", dependencies = TRUE)}.
1616
#'
17-
#' @import shiny leaflet gargoyle
1817
#' @importFrom magrittr "%>%"
18+
#' @import bslib gargoyle leaflet shiny
1919
NULL

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# shinyscholar (v0.3.0)
1+
# shinyscholar (v0.4.0)
2+
23
[![R CMD check](https://github.com/simon-smart88/shinyscholar/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/simon-smart88/shinyscholar/actions/workflows/R-CMD-check.yaml)
34
[![CRAN Status](https://www.r-pkg.org/badges/version/shinyscholar)](https://cran.r-project.org/package=shinyscholar)
45
[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/shinyscholar)](https://cran.r-project.org/package=shinyscholar)
@@ -217,14 +218,12 @@ Further modules can be added using `create_module()` which creates the four file
217218
Support for asynchronous operations was added in v0.2.0 using the new `ExtendedTask` feature added in `{shiny}` v1.8.1. This has the advantage of allowing long-running operations to run in the background whilst the app remains responsive to the user and any other users connected to the same instance. Running modules asynchronously increases complexity however and requires several changes to structure of modules and the app itself. The `select_async` module contains an implementation that is functionally identical to `select_query` but runs asynchronously.
218219

219220
##### Running tasks
220-
`common$tasks` is a list that stores details of all the asynchronous tasks. Each task is added to the list above the `observeEvent()` in the `<identifier>_module_server` function as `common$tasks$<identifier>`. The task contains the module's function wrapped by `promises::future_promise()` and bound to a `bslib::bind_task_button()` which disables the button when the task is running:
221+
`common$tasks` is a list that stores details of all the asynchronous tasks. Each task is added to the list above the `observeEvent()` in the `<identifier>_module_server` function as `common$tasks$<identifier>`. The task contains the module's function wrapped by `mirai::mirai()` and bound to a `bslib::bind_task_button()` which disables the button when the task is running:
221222

222223
```R
223224
common$tasks$<identifier> <- ExtendedTask$new(function(...) {
224-
promises::future_promise({
225-
<identifer>(...)
226-
})
227-
}) |> bslib::bind_task_button("run")
225+
mirai::mirai(run(...), environment(), .args = list(run = <identifier>))
226+
}) |> bslib::bind_task_button("run")
228227
```
229228

230229
The task is invoked inside the `observeEvent()` by calling `common$tasks$<identifier>$invoke()` with the arguments of the module's function. As in the default implementation, metadata should be stored at this point when the function is called.

inst/app_skeleton/DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Authors@R:
66
c(person("Simon E. H.", "Smart", email = "simon.smart@cantab.net", role = c("aut","cre")))
77
Depends:
88
R (>= 3.5.0),
9+
bslib,
910
gargoyle,
1011
shiny (>= 1.8.1)
1112
Imports:

0 commit comments

Comments
 (0)