-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This resolves #812 CC @lcd2yyz This is just a frontend proposition for the landing page functionality. This could be used to present a welcome statement or a disclaimer that requires a consent. Below is a code for the simple teal app that starts with a landing page specification. Currently this PR is build upon `shinyalert::shinyalert` function, but once this is accepted I will take out just the ingredients out of this functions and put in teal so that we don't need to include another dependency in `teal` package. A user is able to customize the landing page with `title` (1), `text` (2) and `button` (3) parameters of `langing` list argument in `teal::init` ![image](https://github.com/insightsengineering/teal/assets/133694481/6bb33779-0cca-4f3c-a32e-8f171c00430c) <details><summary>R code</summary> ```r new_iris <- transform(iris, id = seq_len(nrow(iris))) new_mtcars <- transform(mtcars, id = seq_len(nrow(mtcars))) app <- init( data = teal_data( dataset("new_iris", new_iris), dataset("new_mtcars", new_mtcars), code = " new_iris <- transform(iris, id = seq_len(nrow(iris))) new_mtcars <- transform(mtcars, id = seq_len(nrow(mtcars))) " ), modules = modules( module( label = "data source", server = function(input, output, session, data) {}, ui = function(id, ...) div(p("information about data source")), datanames = "all" ), example_module(label = "example teal module"), module( "Iris Sepal.Length histogram", server = function(input, output, session, data) { output$hist <- renderPlot( hist(data[["new_iris"]]()$Sepal.Length) ) }, ui = function(id, ...) { ns <- NS(id) plotOutput(ns("hist")) }, datanames = "new_iris" ) ), title = "App title", filter = teal_slices( teal_slice(dataname = "new_iris", varname = "Species"), teal_slice(dataname = "new_iris", varname = "Sepal.Length"), teal_slice(dataname = "new_mtcars", varname = "cyl"), exclude_varnames = list(new_iris = c("Sepal.Width", "Petal.Width")), mapping = list( `example teal module` = "new_iris Species", `Iris Sepal.Length histogram` = "new_iris Species", global_filters = "new_mtcars cyl" ) ), header = tags$h1("Sample App"), footer = tags$p("Copyright 2017 - 2023"), landing = list( title = 'Disclaimer', text = 'By agreeing to this statement you confirm you accept A, B and C.', button = 'Agree' ) ) if (interactive()) { shinyApp(app$ui, app$server) } ``` </details> --------- Signed-off-by: Marcin <[email protected]> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Aleksander Chlebowski <[email protected]> Co-authored-by: Pawel Rucki <[email protected]> Co-authored-by: Dawid Kałędkowski <[email protected]>
- Loading branch information
1 parent
8b2653d
commit 7c10cfa
Showing
13 changed files
with
252 additions
and
17 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
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
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
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
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,88 @@ | ||
#' 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") | ||
#' ), | ||
#' example_module() | ||
#' ) | ||
#' ) | ||
#' 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("read", "Read more", | ||
#' onclick = "window.open('http://google.com', '_blank')" | ||
#' ), | ||
#' actionButton("close", "Reject", onclick = "window.close()") | ||
#' ) | ||
#' ), | ||
#' example_module() | ||
#' ) | ||
#' ) | ||
#' | ||
#' if (interactive()) { | ||
#' shinyApp(app2$ui, app2$server) | ||
#' } | ||
#' | ||
#' @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 | ||
} |
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
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
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
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
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.