Skip to content

Commit

Permalink
Merge pull request #9 from agenius-mohammed-ali/Update-shiny-modules
Browse files Browse the repository at this point in the history
Update shiny modules
  • Loading branch information
agenius-mohammed-ali authored Aug 10, 2021
2 parents 2d7d4f3 + 9e8283e commit 3e93354
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 167 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
.Ruserdata
**/.DS_Store
vignettes/*.html
vignettes/*.R
**/log
.project
91 changes: 20 additions & 71 deletions tests/testthat/test_app_reset.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,72 +14,35 @@ test_that("app_reset - no reset button", {
})

test_that("app_reset - reset button - no pending", {
testServer(app_reset,
expr = {
suppressWarnings({
session$setInputs(resetButton = TRUE,
resetPending = FALSE,
logger = periscope:::fw_get_user_log())

expect_null(session$getReturned())
expect_silent(app_reset(input = list(resetButton = TRUE, resetPending = FALSE),
output = list(),
session = MockShinySession$setInputs(resetButton = TRUE,
resetPending = FALSE),
logger = periscope:::fw_get_user_log()))
})
})
expect_silent(app_reset(input = list(resetButton = TRUE, resetPending = FALSE),
output = list(),
session = MockShinySession$setInputs(resetButton = TRUE,
resetPending = FALSE),
logger = periscope:::fw_get_user_log()))
})

test_that("app_reset - no reset button - with pending", {
testServer(app_reset,
expr = {
suppressWarnings({
session$setInputs(resetButton = FALSE,
resetPending = TRUE,
logger = periscope:::fw_get_user_log())
expect_null(session$getReturned())
expect_silent(app_reset(input = list(resetButton = FALSE, resetPending = TRUE),
output = list(),
session = MockShinySession$setInputs(resetButton = TRUE,
resetPending = FALSE),
logger = periscope:::fw_get_user_log()))
})
})
expect_silent(app_reset(input = list(resetButton = FALSE, resetPending = TRUE),
output = list(),
session = MockShinySession$setInputs(resetButton = TRUE,
resetPending = FALSE),
logger = periscope:::fw_get_user_log()))
})

test_that("app_reset - reset button - with pending", {
testServer(app_reset,
expr = {
suppressWarnings({
session$setInputs(resetButton = TRUE,
resetPending = TRUE,
logger = periscope:::fw_get_user_log())
expect_null(session$getReturned())
expect_silent(app_reset(input = list(resetButton = TRUE, resetPending = TRUE),
output = list(),
session = MockShinySession$setInputs(resetButton = TRUE,
resetPending = FALSE),
logger = periscope:::fw_get_user_log()))
})
})
expect_silent(app_reset(input = list(resetButton = TRUE, resetPending = TRUE),
output = list(),
session = MockShinySession$setInputs(resetButton = TRUE,
resetPending = FALSE),
logger = periscope:::fw_get_user_log()))
})

test_that("app_reset", {
testServer(app_reset,
expr = {
suppressWarnings({
session$setInputs(resetButton = FALSE,
resetPending = FALSE,
logger = periscope:::fw_get_user_log())
expect_null(session$getReturned())
expect_silent(app_reset(input = list(resetButton = FALSE, resetPending = FALSE),
output = list(),
session = MockShinySession$setInputs(resetButton = TRUE,
resetPending = FALSE),
logger = periscope:::fw_get_user_log()))
})
})
expect_silent(app_reset(input = list(resetButton = FALSE, resetPending = FALSE),
output = list(),
session = MockShinySession$setInputs(resetButton = TRUE,
resetPending = FALSE),
logger = periscope:::fw_get_user_log()))
})

test_that(".appReset", {
Expand All @@ -92,17 +55,3 @@ test_that(".appReset", {
expect_equal(class(reset)[[1]], "Observer")
expect_equal(class(reset)[[2]], "R6")
})

test_that("app_reset_old_style_call", {
testServer(app_reset,
expr = {
suppressWarnings({
reset <- shiny::callModule(app_reset,
"reset",
logger = periscope:::fw_get_user_log())
expect_equal(class(reset)[[1]], "Observer")
expect_equal(class(reset)[[2]], "R6")
})
})
})

26 changes: 8 additions & 18 deletions tests/testthat/test_body_footer.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,13 @@ test_that(".bodyFooter", {
})

test_that("boody_footer", {
testServer(boody_footer,
expr = {
session$setInputs(logdata = data)
expect_silent(boody_footer)
})
expect_silent(boody_footer(input = list(),
output = list(),
session = MockShinySession$new(),
logdata = data))

testServer(boody_footer,
expr = {
session$setInputs(logdata = data2)
expect_silent(boody_footer)
})
})

test_that("boody_footer2", {
testServer(boody_footer,
expr = {
session$setInputs(logdata = data2)
expect_silent(boody_footer)
})
expect_silent(boody_footer(input = list(),
output = list(),
session = MockShinySession$new(),
logdata = data2))
})
1 change: 0 additions & 1 deletion tests/testthat/test_downloadable_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ test_that("downloadableTable", {
tabledata = data,
selection = mydataRowIds))
})

})
46 changes: 17 additions & 29 deletions vignettes/downloadFile-module.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ vignette: >

# Overview

## Purpose
## Purpose

This *Shiny Module* was created in order to provide a consistent-looking and
easy-to-use button that facilitates one or multiple types of file downloads.
Expand All @@ -36,21 +36,16 @@ easy-to-use button that facilitates one or multiple types of file downloads.
Shiny modules consist of a pair of functions that modularize, or package, a
small piece of reusable functionality. The UI function is called directly by
the user to place the UI in the correct location (as with other shiny UI
objects). The server function is not called directly by the user of the module.
Instead the module server function is called only once to set it up using the
shiny::callModule function inside the server function (i.e. user-local session
scope. The callModule function supplies the first three arguments of the
Shiny Module's function inputs - the input, output, and session. Additional
arguments supplied by the user in the callModule function are passed to the
specific shiny module that is called. There can be additional helper functions
that are a part of a shiny module.
objects). The module server function that is called only once to set it up using the
module name as a function inside the server function (i.e. user-local session
scope. The function first arguments is string represents the module id (the same id used in module UI function). Additional arguments can be supplied by the user based on the specific shiny module that is called. There can be additional helper functions that are a part of a shiny module.

The **downloadFile** Shiny Module is a part of the *periscope* package and
consists of the following functions:

* **downloadFileButton** - the UI function to place the button in the
application
* **downloadFile** - the Server function supplied to callModule.
application.
* **downloadFile** - the server function to be called inside server_local.R.
* **downloadFile_ValidateTypes** - a helper function that will check a given
list of file types and warn the caller if the list contains an invalid or
unsupported type.
Expand Down Expand Up @@ -101,13 +96,8 @@ downloadFileButton("object_id2",

## downloadFile

The **downloadFile** function is not called directly - instead a call to
shiny::callModule is made inside the server.R (or equivalent) file to initialize
the module.
The **downloadFile** function is called directly. The call consists of the following:

The call consists of the following:

* the name of the module - unquoted
* the unique object ID that was provided to downloadFileButton when creating
the UI object
* the logging logger to be used
Expand Down Expand Up @@ -142,20 +132,18 @@ to the user from the application.
# Inside server_local.R
#single download type
callModule(downloadFile,
"object_id1",
logger = ss_userAction.Log,
filenameroot = "mydownload1",
datafxns = list(csv = mydatafxn1),
aspectratio = 1)
downloadFile("object_id1",
logger = ss_userAction.Log,
filenameroot = "mydownload1",
datafxns = list(csv = mydatafxn1),
aspectratio = 1)
#multiple download types
callModule(downloadFile,
"object_id2",
logger = ss_userAction.Log,
filenameroot = "mytype2",
datafxns = list(csv = mydatafxn1, xlsx = mydatafxn2),
aspectratio = 1)
downloadFile("object_id2",
logger = ss_userAction.Log,
filenameroot = "mytype2",
datafxns = list(csv = mydatafxn1, xlsx = mydatafxn2),
aspectratio = 1)
```


Expand Down
34 changes: 12 additions & 22 deletions vignettes/downloadablePlot-module.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ vignette: >

# Overview

## Purpose
## Purpose

This *Shiny Module* was created in order to provide an
easy-to-use downloadFileButton for a plot that is automatically created, linked
Expand Down Expand Up @@ -47,14 +47,9 @@ button
Shiny modules consist of a pair of functions that modularize, or package, a
small piece of reusable functionality. The UI function is called directly by
the user to place the UI in the correct location (as with other shiny UI
objects). The server function is not called directly by the user of the module.
Instead the module server function is called only once to set it up using the
shiny::callModule function inside the server function (i.e. user-local session
scope. The callModule function supplies the first three arguments of the
Shiny Module's function inputs - the input, output, and session. Additional
arguments supplied by the user in the callModule function are passed to the
specific shiny module that is called. There can be additional helper functions
that are a part of a shiny module.
objects). The module server function that is called only once to set it up using the
module name as a function inside the server function (i.e. user-local session
scope. The function first arguments is string represents the module id (the same id used in module UI function). Additional arguments can be supplied by the user based on the specific shiny module that is called. There can be additional helper functions that are a part of a shiny module.


## downloadablePlotUI
Expand Down Expand Up @@ -93,13 +88,8 @@ downloadablePlotUI("object_id1",

## downloadablePlot

The **downloadablePlot** function is not called directly - instead a call to
shiny::callModule is made inside the server.R (or equivalent) file to initialize
the module.
The **downloadablePlot** function is also called directly. The call consists of the following:

The call consists of the following:

* the name of the module - unquoted
* the unique object ID that was provided to downloadablePlotUI when creating
the UI object
* the logging logger to be used
Expand Down Expand Up @@ -139,13 +129,13 @@ to the user from the application. All the above requirements apply.
```{r, eval = F}
# Inside server_local.R
callModule(downloadablePlot,
"object_id1",
logger = ss_userAction.Log,
filenameroot = "mydownload1",
aspectratio = 1.33,
downloadfxns = list(png = myplotfxn, tsv = mydatafxn),
visibleplot = myplotfxn)
downloadablePlot("object_id1",
logger = ss_userAction.Log,
filenameroot = "mydownload1",
aspectratio = 1.33,
downloadfxns = list(png = myplotfxn, tsv = mydatafxn),
visibleplot = myplotfxn)
```

<br>
Expand Down
40 changes: 15 additions & 25 deletions vignettes/downloadableTable-module.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ vignette: >

# Overview

## Purpose
## Purpose

This *Shiny Module* was created in order to provide a consistent-looking and
easy-to-use table including a downloadFileButton that is automatically created,
Expand Down Expand Up @@ -48,21 +48,16 @@ scrolling (no paging)
Shiny modules consist of a pair of functions that modularize, or package, a
small piece of reusable functionality. The UI function is called directly by
the user to place the UI in the correct location (as with other shiny UI
objects). The server function is not called directly by the user of the module.
Instead the module server function is called only once to set it up using the
shiny::callModule function inside the server function (i.e. user-local session
scope. The callModule function supplies the first three arguments of the
Shiny Module's function inputs - the input, output, and session. Additional
arguments supplied by the user in the callModule function are passed to the
specific shiny module that is called. There can be additional helper functions
that are a part of a shiny module.
objects). The module server function that is called only once to set it up using the
module name as a function inside the server function (i.e. user-local session
scope. The function first arguments is string represents the module id (the same id used in module UI function). Additional arguments can be supplied by the user based on the specific shiny module that is called. There can be additional helper functions that are a part of a shiny module.

The **downloadableTable** Shiny Module is a part of the *periscope* package and
consists of the following functions:

* **downloadableTableUI** - the UI function to place the table in the
application
* **downloadableTable** - the Server function supplied to callModule.
* **downloadableTable** - the server function to be called inside server_local.R.


## downloadableTableUI
Expand Down Expand Up @@ -99,13 +94,8 @@ downloadableTableUI("object_id1",

## downloadableTable

The **downloadableTable** function is not called directly - instead a call to
shiny::callModule is made inside the server.R (or equivalent) file to initialize
the module.
The **downloadableTable** function is called directly. The call consists of the following:

The call consists of the following:

* the name of the module - unquoted
* the unique object ID that was provided to downloadableTableUI when creating
the UI object
* the logging logger to be used
Expand Down Expand Up @@ -138,7 +128,7 @@ to the user from the application. All the above requirements apply.

**Reactive Return Value**

The callModule function returns a reactive expression containing the selected
The server function returns a reactive expression containing the selected
rows (data, not references, rownumbers, etc - the actual table row data). This
allows the user to capture this to update another table, chart, etc. as desired.
It is acceptable to ignore the return value as well if this functionality is not
Expand All @@ -148,14 +138,14 @@ needed.
```{r, eval = F}
# Inside server_local.R
selectedrows <- callModule(downloadableTable,
"object_id1",
logger = ss_userAction.Log,
filenameroot = "mydownload1",
downloaddatafxns = list(csv = mydatafxn1, tsv = mydatafxn2),
tabledata = mydatafxn3,
rownames = FALSE,
caption = "This is a great table! By: Me" )
selectedrows <- downloadableTable("object_id1",
logger = ss_userAction.Log,
filenameroot = "mydownload1",
downloaddatafxns = list(csv = mydatafxn1,
tsv = mydatafxn2),
tabledata = mydatafxn3,
rownames = FALSE,
caption = "This is a great table! By: Me" )
# selectedrows is the reactive return value, captured for later use
```
Expand Down

0 comments on commit 3e93354

Please sign in to comment.