Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

812 landing popup #934

Merged
merged 108 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 103 commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
2e06eaf
#812 proposition for landing popup with shinyalert package
m7pr Oct 12, 2023
62b5f5b
Merge 2e06eaff883e4bd7dc8f692625ddc45c09fea5da into e722c601d7a902c2b…
m7pr Oct 12, 2023
713b37f
[skip actions] Restyle files
github-actions[bot] Oct 12, 2023
18834f4
Empty-Commit
m7pr Oct 12, 2023
02b83fd
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 12, 2023
e920f50
Empty-Commit
m7pr Oct 12, 2023
3dcccf3
typo
m7pr Oct 12, 2023
5d33893
Empty-Commit
m7pr Oct 13, 2023
f973beb
rename landing param to extra_server in teal
m7pr Oct 13, 2023
ebe79c1
Merge branch 'main' into 812_landing_popup@main
m7pr Oct 13, 2023
a04ee4a
move out landing popup to teal.modules.general
m7pr Oct 13, 2023
34ce78b
merge
m7pr Oct 13, 2023
aa253fa
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 13, 2023
6666237
update examples
m7pr Oct 13, 2023
eb3bffa
add teal.modules.general to Suggests
m7pr Oct 16, 2023
0bd57c6
remove extra_server parameter
m7pr Oct 16, 2023
b86ccff
Remove module labelled "Landing Popup" from modules list and pass it …
m7pr Oct 16, 2023
4f01d31
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 16, 2023
5d18417
fix teal::init server usage of landing popup thanks to @chlebowa ideas
m7pr Oct 17, 2023
843a590
Merge branch 'main' into 812_landing_popup@main
m7pr Oct 23, 2023
a0e2ce2
812 landing popup mod@812 landing popup@main (#936)
chlebowa Oct 23, 2023
5b34678
move extract_landing and drop_landing into modules.R
m7pr Oct 23, 2023
5448206
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 23, 2023
ec595bc
extend module
m7pr Oct 23, 2023
b03ddc1
rebuild manual pages
m7pr Oct 23, 2023
6fd0b41
merge
m7pr Oct 23, 2023
bdc373b
Empty-Commit
m7pr Oct 23, 2023
464c42c
extend assertion of class of elements passed to modules()
m7pr Oct 23, 2023
11955bc
update teal init note
m7pr Oct 23, 2023
881d88f
typo
m7pr Oct 23, 2023
69d5c71
change extract/drop_landing into extract/drop_module with class argument
m7pr Oct 23, 2023
f342db9
Merge 69d5c714cd18f48f87eb22108a0a2c8ad3691236 into a71f06cb04b6101d9…
m7pr Oct 23, 2023
3604eb0
[skip actions] Restyle files
github-actions[bot] Oct 23, 2023
daa14c6
Update R/init.R
m7pr Oct 23, 2023
cce8655
Update R/init.R
m7pr Oct 23, 2023
ed6bafc
Update NEWS.md
m7pr Oct 24, 2023
98b2e0a
Update R/modules.R
m7pr Oct 24, 2023
a629e3c
Update R/modules.R
m7pr Oct 24, 2023
f0bbf52
Update R/modules.R
m7pr Oct 24, 2023
1ea1950
Merge f0bbf5218552a86a6304fd16e87a036ab6c7cc5e into a71f06cb04b6101d9…
m7pr Oct 24, 2023
1e1fa37
[skip actions] Restyle files
github-actions[bot] Oct 24, 2023
f26ee16
Update R/modules.R
m7pr Oct 24, 2023
c47552e
change the condition on the lenght of the landing
m7pr Oct 24, 2023
7bebae8
Merge branch '812_landing_popup@main' of https://github.com/insightse…
m7pr Oct 24, 2023
93eee85
Update R/modules.R
m7pr Oct 24, 2023
0fa96e6
rebuild documentation
m7pr Oct 24, 2023
c3e928b
Merge branch '812_landing_popup@main' of https://github.com/insightse…
m7pr Oct 24, 2023
deed4d8
Merge c3e928b7638fb14474fe3d786c120c726df2f449 into a71f06cb04b6101d9…
m7pr Oct 24, 2023
4d54613
[skip actions] Restyle files
github-actions[bot] Oct 24, 2023
affd16f
fix drop/extract_module
m7pr Oct 24, 2023
3109ee2
Merge branch '812_landing_popup@main' of https://github.com/insightse…
m7pr Oct 24, 2023
7743f6e
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 24, 2023
530d1f5
add dots at the end of sentences
m7pr Oct 24, 2023
26c82f6
remove type from modules
m7pr Oct 24, 2023
ad0ad10
move tm_landing_popup from tmg to teal
m7pr Oct 24, 2023
55e7919
merge
m7pr Oct 24, 2023
83878e8
Merge 55e791966f05c03287dac7b63e62117bd2a81401 into a71f06cb04b6101d9…
m7pr Oct 24, 2023
2b4ae97
[skip actions] Restyle files
github-actions[bot] Oct 24, 2023
c92e925
bind drop_module and extract_module in one documentation page
m7pr Oct 24, 2023
684ef3f
Merge branch '812_landing_popup@main' of https://github.com/insightse…
m7pr Oct 24, 2023
3da289f
remove a note from init about tm_landing_popup
m7pr Oct 24, 2023
d9c7472
Update R/modules.R
m7pr Oct 24, 2023
3cacf36
remove match.arg for type from init
m7pr Oct 24, 2023
ff1cf3b
Merge branch '812_landing_popup@main' of https://github.com/insightse…
m7pr Oct 24, 2023
95397de
extend tm_landing_popup examples with another module
m7pr Oct 24, 2023
e6049a0
bring a more meanigful warning for situation where user provided only…
m7pr Oct 24, 2023
7d75399
remove outdated parameter from documentaiton
m7pr Oct 24, 2023
1dffcfd
remove unneeded div from the examples
m7pr Oct 24, 2023
8f111e8
shiny tag -> siny.tag documentation change
m7pr Oct 24, 2023
4eb1a39
example with the closing of the browser
m7pr Oct 24, 2023
c6a0203
adjust text in docs
m7pr Oct 24, 2023
7b43211
lintr changes
m7pr Oct 24, 2023
0ad23da
Merge 7b43211a677310c28c45140334dcec38ee2f2073 into a71f06cb04b6101d9…
m7pr Oct 24, 2023
f0f60aa
[skip actions] Restyle files
github-actions[bot] Oct 24, 2023
1d21305
Empty-Commit
m7pr Oct 24, 2023
39975e6
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 24, 2023
16af597
rename tm_landing_popup to landing_popup_module
m7pr Oct 24, 2023
e95511a
Merge branch '812_landing_popup@main' of https://github.com/insightse…
m7pr Oct 24, 2023
0179152
specify content parameter in landind_popup_module
m7pr Oct 25, 2023
9e700ab
Update R/landing_popup_module.R
m7pr Oct 25, 2023
bc25503
extend logging in reporter_previewer_module
m7pr Oct 25, 2023
09c7ab7
Merge branch '812_landing_popup@main' of https://github.com/insightse…
m7pr Oct 25, 2023
ab29aab
Update R/landing_popup_module.R
m7pr Oct 25, 2023
064e382
rebuild documentaion
m7pr Oct 25, 2023
64f7215
Update R/reporter_previewer_module.R
m7pr Oct 25, 2023
91286e3
Merge 64f72154119f47844467d46ea47f80ab516a5ef6 into a71f06cb04b6101d9…
m7pr Oct 25, 2023
132872b
change man name for extract/drop_modules to module_management
m7pr Oct 25, 2023
2d25bd9
[skip actions] Restyle files
github-actions[bot] Oct 25, 2023
00670d7
Merge branch '812_landing_popup@main' of https://github.com/insightse…
m7pr Oct 25, 2023
4ceb8eb
Merge branch '812_landing_popup@main' of https://github.com/insightse…
m7pr Oct 25, 2023
30fb85d
Update R/landing_popup_module.R
m7pr Oct 25, 2023
4f651c4
Title case warning
m7pr Oct 25, 2023
0200dc2
Update R/init.R
m7pr Oct 25, 2023
87af18a
make it easier to read the return value for modules_management
m7pr Oct 25, 2023
2434c2b
Merge branch '812_landing_popup@main' of https://github.com/insightse…
m7pr Oct 25, 2023
22e057e
rebuild man
m7pr Oct 25, 2023
71c1676
Update R/modules.R
m7pr Oct 25, 2023
9de95b1
Update R/modules.R
m7pr Oct 25, 2023
970ac66
update NEWS
m7pr Oct 25, 2023
8825276
Merge branch '812_landing_popup@main' of https://github.com/insightse…
m7pr Oct 25, 2023
989f30d
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 25, 2023
0670e3b
Empty-Commit
m7pr Oct 25, 2023
007c0e1
remove unnecessary error message
m7pr Oct 25, 2023
0b4ddf8
use example_module() in simple teal examples
m7pr Oct 25, 2023
9e7ecfb
update landing examples
m7pr Oct 25, 2023
e847ac9
Merge branch 'main' into 812_landing_popup@main
m7pr Oct 25, 2023
10ac427
merge 2 example for landing page popup
m7pr Oct 25, 2023
3300979
Empty-Commit
m7pr Oct 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Collate:
'include_css_js.R'
'modules.R'
'init.R'
'landing_popup_module.R'
'module_filter_manager.R'
'module_nested_tabs.R'
'module_snapshot_manager.R'
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export(get_code_tdata)
export(get_join_keys)
export(get_metadata)
export(init)
export(landing_popup_module)
export(module)
export(modules)
export(new_tdata)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Added internal functions for storing and restoring of `teal_slices` objects.
* Filter state snapshots can now be uploaded from file. See `?snapshot`.
* Added argument to `teal_slices` and made modifications to `init` to enable tagging `teal_slices` with an app id to safely upload snapshots from disk.
* Added `landing_popup_module` function which creates a module that will display a popup when the app starts. The popup will block access to the app until it is dismissed.

# teal 0.14.0

Expand Down
8 changes: 8 additions & 0 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ init <- function(data,
modules <- do.call(teal::modules, modules)
}

landing <- extract_module(modules, "teal_module_landing")
if (length(landing) > 1L) stop("Only one `landing_popup_module` can be used.")
modules <- drop_module(modules, "teal_module_landing")

# resolve modules datanames
datanames <- teal.data::get_dataname(data)
join_keys <- data$get_join_keys()
Expand Down Expand Up @@ -223,6 +227,10 @@ init <- function(data,
res <- list(
ui = ui_teal_with_splash(id = id, data = data, title = title, header = header, footer = footer),
server = function(input, output, session) {
if (length(landing) == 1L) {
landing_module <- landing[[1L]]
do.call(landing_module$server, c(list(id = "landing_module_shiny_id"), landing_module$server_args))
}
# copy object so that load won't be shared between the session
data <- data$copy(deep = TRUE)
filter <- deep_copy_filter(filter)
Expand Down
118 changes: 118 additions & 0 deletions R/landing_popup_module.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#' Landing Popup Module
#'
#' @description Creates a landing welcome popup for `teal` applications.
#'
#' This module is used to display a popup dialog when the application starts.
#' The dialog blocks the access to the application and must be closed with a button before the application is viewed.
#'
#' @param label `character(1)` the label of the module.
#' @param title `character(1)` the text to be displayed as a title of the popup.
#' @param content The content of the popup. Passed to `...` of `shiny::modalDialog`. Can be a `character`
#' or a list of `shiny.tag`s. See examples.
#' @param buttons `shiny.tag` or a list of tags (`tagList`). Typically a `modalButton` or `actionButton`. See examples.
#'
#' @return A `teal_module` (extended with `teal_landing_module` class) to be used in `teal` applications.
#'
#' @examples
#' app1 <- teal::init(
#' data = teal.data::dataset("iris", iris),
#' modules = teal::modules(
#' teal::landing_popup_module(
#' content = "A place for the welcome message or a disclaimer statement.",
#' buttons = modalButton("Proceed")
#' ),
#' module(
m7pr marked this conversation as resolved.
Show resolved Hide resolved
#' label = "example module",
#' server = function(input, output, session, data) {},
#' ui = function(id, ...) div(p("Example text"))
#' )
#' )
#' )
#' if (interactive()) {
#' shinyApp(app1$ui, app1$server)
#' }
#'
#' app2 <- teal::init(
#' data = teal.data::dataset("iris", iris),
#' modules = teal::modules(
#' teal::landing_popup_module(
#' title = "Welcome",
#' content = tags$b(
#' "A place for the welcome message or a disclaimer statement.",
#' style = "color: red;"
#' ),
#' buttons = tagList(
#' modalButton("Proceed"),
#' actionButton("close", "Read more",
#' onclick = "window.open('http://google.com', '_blank')"
#' )
#' )
#' ),
#' module(
#' label = "example module",
#' server = function(input, output, session, data) {},
#' ui = function(id, ...) div(p("Example text"))
#' )
#' )
#' )
#'
#' if (interactive()) {
#' shinyApp(app2$ui, app2$server)
#' }
#'
#' app3 <- teal::init(
#' data = teal.data::dataset("iris", iris),
#' modules = teal::modules(
#' teal::landing_popup_module(
#' title = "Welcome",
#' content = "App will close, once you click the rejection button!",
#' buttons = tagList(
#' modalButton("Proceed"),
#' actionButton("close", "Reject", onclick = "window.close()")
#' )
#' ),
#' module(
m7pr marked this conversation as resolved.
Show resolved Hide resolved
#' label = "example module",
#' server = function(input, output, session, data) {},
#' ui = function(id, ...) div(p("Example text"))
#' )
#' )
#' )
#'
#' if (interactive()) {
#' shinyApp(app3$ui, app3$server, options = list(launch.browser = TRUE))
#' }
#'
#' @export
landing_popup_module <- function(label = "Landing Popup",
title = NULL,
content = NULL,
buttons = modalButton("Accept")) {
checkmate::assert_string(label)
checkmate::assert_string(title, null.ok = TRUE)
checkmate::assert_multi_class(
content,
classes = c("character", "shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE
)
checkmate::assert_multi_class(buttons, classes = c("shiny.tag", "shiny.tag.list"))

logger::log_info("Initializing landing_popup_module")

module <- module(
label = label,
server = function(id) {
moduleServer(id, function(input, output, session) {
showModal(
modalDialog(
id = "landingpopup",
title = title,
content,
footer = buttons
)
)
})
}
)
class(module) <- c("teal_module_landing", class(module))
module
}
11 changes: 1 addition & 10 deletions R/module_teal.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,7 @@ srv_teal <- function(id, modules, raw_data, filter = teal_slices()) {
})

reporter <- teal.reporter::Reporter$new()
is_any_previewer <- function(modules) {
if (inherits(modules, "teal_modules")) {
any(unlist(lapply(modules$children, is_any_previewer), use.names = FALSE))
} else if (inherits(modules, "teal_module_previewer")) {
TRUE
} else {
FALSE
}
}
if (is_arg_used(modules, "reporter") && !is_any_previewer(modules)) {
if (is_arg_used(modules, "reporter") && length(extract_module(modules, "teal_module_previewer")) == 0) {
modules <- append_module(modules, reporter_previewer_module())
}

Expand Down
39 changes: 38 additions & 1 deletion R/modules.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ modules <- function(..., label = "root") {
)
}

#' Function which appends a teal_module onto the children of a teal_modules object
#' Append a `teal_module` to `children` of a `teal_modules` object
#' @keywords internal
#' @param modules `teal_modules`
#' @param module `teal_module` object to be appended onto the children of `modules`
Expand All @@ -103,6 +103,43 @@ append_module <- function(modules, module) {
modules
}

#' Extract/Remove module(s) of specific class
#'
#' Given a `teal_module` or a `teal_modules`, return the elements of the structure according to `class`.
#'
#' @param modules `teal_modules`
m7pr marked this conversation as resolved.
Show resolved Hide resolved
#' @param class The class name of `teal_module` to be extracted or dropped.
#' @keywords internal
#' @return
#' For `extract_module`, a `teal_module` of class `class` or `teal_modules` containing modules of class `class`.
#' For `drop_module`, the opposite, which is all `teal_modules` of class other than `class`.
#' @rdname module_management
extract_module <- function(modules, class) {
if (inherits(modules, class)) {
modules
} else if (inherits(modules, "teal_module")) {
NULL
} else if (inherits(modules, "teal_modules")) {
Filter(function(x) length(x) > 0L, lapply(modules$children, extract_module, class))
}
}

#' @keywords internal
#' @return `teal_modules`
#' @rdname module_management
drop_module <- function(modules, class) {
if (inherits(modules, class)) {
NULL
} else if (inherits(modules, "teal_module")) {
modules
} else if (inherits(modules, "teal_modules")) {
do.call(
"modules",
pawelru marked this conversation as resolved.
Show resolved Hide resolved
c(Filter(function(x) length(x) > 0L, lapply(modules$children, drop_module, class)), label = modules$label)
)
}
}

#' Does the object make use of the `arg`
#'
#' @param modules (`teal_module` or `teal_modules`) object
Expand Down
9 changes: 7 additions & 2 deletions R/reporter_previewer_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@
#'
#' If you are creating a `teal` application using [teal::init()] then this
#' module will be added to your application automatically if any of your `teal modules`
#' support report generation
#' support report generation.
#'
#' @inheritParams module
#' @param server_args (`named list`)\cr
#' Arguments passed to [teal.reporter::reporter_previewer_srv()].
#' @return `teal_module` containing the `teal.reporter` previewer functionality
#' @return `teal_module` (extended with `teal_module_previewer` class) containing the `teal.reporter` previewer
#' functionality.
#' @export
reporter_previewer_module <- function(label = "Report previewer", server_args = list()) {
checkmate::assert_string(label)
checkmate::assert_list(server_args, names = "named")
checkmate::assert_true(all(names(server_args) %in% names(formals(teal.reporter::reporter_previewer_srv))))

logger::log_info("Initializing reporter_previewer_module")

srv <- function(id, reporter, ...) {
teal.reporter::reporter_previewer_srv(id, reporter, ...)
}
Expand All @@ -32,6 +35,8 @@ reporter_previewer_module <- function(label = "Report previewer", server_args =
server = srv, ui = ui,
server_args = server_args, ui_args = list(), datanames = NULL
)
# Module is created with a placeholder label and the label is changed later.
# This is to prevent another module being labeled "Report previewer".
class(module) <- c("teal_module_previewer", class(module))
module$label <- label
module
Expand Down
3 changes: 3 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ reference:
- reporter_previewer_module
- TealReportCard
- report_card_template
- title: Landing Popup
contents:
- landing_popup_module
- title: Functions for Module Developers
contents:
- tdata
Expand Down
4 changes: 2 additions & 2 deletions man/append_module.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 103 additions & 0 deletions man/landing_popup_module.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading