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

Data module as tab@669 insert UI@main #1273

Merged
merged 22 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5053ada
feat: move data popup as a module tab
vedhav Jul 23, 2024
6fc7d47
fix: remove data module tab when teal_data is the input
vedhav Jul 23, 2024
1ec9272
Merge branch '669_insertUI@main' into data_module_as_tab@669_insertUI…
vedhav Jul 23, 2024
b30f471
chore: simplify the logic without extra arg
vedhav Jul 23, 2024
07cf9e6
fix: disable the modules click during init when teal_data_module is used
vedhav Jul 23, 2024
f284e50
fix: make the bookmark restore work as expected
vedhav Jul 23, 2024
e621db5
Merge remote-tracking branch 'origin/669_insertUI@main' into data_mod…
vedhav Jul 25, 2024
3edf695
Merge branch '669_insertUI@main' into data_module_as_tab@669_insertUI…
vedhav Jul 25, 2024
178068e
fix: move the main teal body class to `ui_teal`
vedhav Jul 25, 2024
364cf16
fix: move setting of bookmark options in the UI
vedhav Jul 25, 2024
321eef8
fix: minor css and icon changes
vedhav Jul 26, 2024
10933a8
fix: toggle sidebar specific to the teal app when run as module
vedhav Jul 26, 2024
9ffeb68
feat: allow `teal_data_module` to be consumed only once
vedhav Jul 26, 2024
cb57ebf
fix: handle NULL input
vedhav Jul 26, 2024
7618327
feat: automatically navigate to the next module when `teal_data_modul…
vedhav Jul 26, 2024
01809f1
Merge branch '669_insertUI@main' into data_module_as_tab@669_insertUI…
vedhav Jul 29, 2024
3b1941c
chore: address @gogonzo comments
vedhav Jul 29, 2024
523a8f0
Merge remote-tracking branch 'origin/669_insertUI@main' into data_mod…
vedhav Jul 29, 2024
670b53e
chore: remove unwanted logic from `modules_bookmarkable`
vedhav Jul 29, 2024
ab0d63d
chore: revert to previous way of excluding tabs when data module is t…
vedhav Jul 30, 2024
219b61c
Update inst/js/sidebar.js
vedhav Jul 30, 2024
198afd2
Merge branch '669_insertUI@main' into data_module_as_tab@669_insertUI…
vedhav Jul 30, 2024
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 NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ S3method(srv_teal_module,default)
S3method(srv_teal_module,teal_module)
S3method(srv_teal_module,teal_modules)
S3method(ui_teal_module,default)
S3method(ui_teal_module,shiny.tag)
S3method(ui_teal_module,teal_module)
S3method(ui_teal_module,teal_modules)
S3method(within,teal_data_module)
Expand Down
47 changes: 20 additions & 27 deletions R/1.0_module_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ NULL
ui_data <- function(id, data, title, header, footer) {
ns <- shiny::NS(id)
shiny::div(
id = ns("content"),
style = "display: inline-block;",
if (inherits(data, "teal_data_module")) {
actionButton(ns("open_teal_data_module"), NULL, icon = icon("database"))
ui_teal_data_module(ns("teal_data_module"), transformer = data)
} else {
NULL
}
Expand Down Expand Up @@ -79,37 +80,29 @@ srv_data <- function(id, data, modules, filter = teal_slices()) {
.fallback_on_failure(this = data, that = reactive(req(FALSE)), label = "Reactive data")
}

setBookmarkExclude("open_teal_data_module")

observeEvent(input$open_teal_data_module, {
if (input$open_teal_data_module > 1) {
footer <- modalButton("Dismiss")
easy_close <- TRUE
} else {
footer <- NULL
easy_close <- FALSE
}
showModal(
modalDialog(
class = ifelse(easy_close, "blur_background", "hide_background"),
tags$div(
ui_teal_data_module(session$ns("teal_data_module"), transformer = data)
),
footer = footer,
easyClose = easy_close
)
)
})

if (inherits(data, "teal_data_module")) {
shinyjs::disable(selector = "#teal_modules-active_tab.nav-tabs a")
shinyjs::click(id = "open_teal_data_module")
shinyjs::disable(selector = sprintf(".teal-body:has('#%s') .nav li a", session$ns("content")))
}

observeEvent(data_validated(), {
removeModal()
showNotification("Data loaded successfully.", duration = 5)
shinyjs::enable(selector = "#teal_modules-active_tab.nav-tabs a")
shinyjs::enable(selector = sprintf(".teal-body:has('#%s') .nav li a", session$ns("content")))
if (isTRUE(attr(data, "once"))) {
# Hiding the data module tab.
shinyjs::hide(
selector = sprintf(
".teal-body:has('#%s') a[data-value='teal_data_module']",
session$ns("content")
)
)
# Clicking the second tab, which is the first module.
shinyjs::runjs(
sprintf(
"document.querySelector('.teal-body:has(#%s) .nav li:nth-child(2) a').click();",
session$ns("content")
)
)
}

is_filter_ok <- check_filter_datanames(filter, teal_data_datanames(data_validated()))
if (!isTRUE(is_filter_ok)) {
Expand Down
3 changes: 1 addition & 2 deletions R/module_bookmark_manager.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ui_bookmark_panel <- function(id, modules) {
class = "btn action-button wunder_bar_button bookmark_manager_button",
title = "Add bookmark",
tags$span(
suppressMessages(icon("solid fa-bookmark")),
suppressMessages(icon("fas fa-bookmark")),
if (any(is_unbookmarkable)) {
tags$span(
sum(is_unbookmarkable),
Expand Down Expand Up @@ -158,7 +158,6 @@ get_bookmarking_option <- function() {
bookmark_option <- getShinyOption("bookmarkStore")
if (is.null(bookmark_option) && identical(getOption("shiny.bookmarkStore"), "server")) {
bookmark_option <- getOption("shiny.bookmarkStore")
# option alone doesn't activate bookmarking - we need to set shinyOptions
}
bookmark_option
}
Expand Down
2 changes: 1 addition & 1 deletion R/module_filter_manager.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ui_filter_manager_panel <- function(id) {
id = ns("show_filter_manager"),
class = "btn action-button wunder_bar_button",
title = "View filter mapping",
suppressMessages(icon("solid fa-grip"))
suppressMessages(icon("fas fa-grip"))
)
}

Expand Down
11 changes: 10 additions & 1 deletion R/module_nested_tabs.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ NULL

#' @rdname module_teal_module
ui_teal_module <- function(id, modules, depth = 0L) {
checkmate::assert_multi_class(modules, c("teal_modules", "teal_module"))
checkmate::assert_multi_class(modules, c("teal_modules", "teal_module", "shiny.tag"))
checkmate::assert_count(depth)
UseMethod("ui_teal_module", modules)
}
Expand All @@ -69,6 +69,9 @@ ui_teal_module.teal_modules <- function(id, modules, depth = 0L) {
names(modules$children),
function(module_id) {
module_label <- modules$children[[module_id]]$label
if (is.null(module_label)) {
module_label <- icon("database")
}
tabPanel(
title = module_label,
value = module_id, # when clicked this tab value changes input$<tabset panel id>
Expand All @@ -84,6 +87,12 @@ ui_teal_module.teal_modules <- function(id, modules, depth = 0L) {
)
}

#' @rdname module_teal_module
#' @export
ui_teal_module.shiny.tag <- function(id, modules, depth = 0L) {
modules
}

#' @rdname module_teal_module
#' @export
ui_teal_module.teal_module <- function(id, modules, depth = 0L) {
Expand Down
24 changes: 18 additions & 6 deletions R/module_teal.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ ui_teal <- function(id,
)
)

bookmark_panel_ui <- ui_bookmark_panel(ns("bookmark_manager"), modules)
data_elem <- ui_data(ns("data"), data = data, title = title, header = header, footer = footer)
if (!is.null(data)) {
modules$children <- c(list(teal_data_module = data_elem), modules$children)
}
tabs_elem <- ui_teal_module(id = ns("teal_modules"), modules = modules)

fluidPage(
Expand All @@ -93,16 +97,19 @@ ui_teal <- function(id,
tags$header(header),
tags$hr(class = "my-2"),
shiny_busy_message_panel,
tabs_elem,
tags$div(
id = "teal-util-icons",
id = ns("tabpanel_wrapper"),
class = "teal-body",
tabs_elem
),
tags$div(
id = ns("options_buttons"),
style = "margin-left: auto;",
data_elem,
ui_bookmark_panel(ns("bookmark_manager"), modules),
bookmark_panel_ui,
tags$button(
class = "btn action-button filter_hamburger", # see sidebar.css for style filter_hamburger
href = "javascript:void(0)",
onclick = "toggleFilterPanel();", # see sidebar.js
onclick = sprintf("toggleFilterPanel('%s');", ns("tabpanel_wrapper")),
title = "Toggle filter panel",
icon("fas fa-bars")
),
Expand All @@ -114,9 +121,10 @@ ui_teal <- function(id,
sprintf(
"
$(document).ready(function() {
$('#teal-util-icons').appendTo('#%s');
$('#%s').appendTo('#%s');
});
",
ns("options_buttons"),
ns("teal_modules-active_tab")
)
)
Expand Down Expand Up @@ -197,5 +205,9 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) {
mapping_table <- srv_filter_manager_panel("filter_manager_panel", slices_global = slices_global)
snapshots <- srv_snapshot_manager_panel("snapshot_manager_panel", slices_global = slices_global)
srv_bookmark_panel("bookmark_manager", modules)

if (inherits(data, "teal_data_module")) {
setBookmarkExclude(c("teal_modules-active_tab"))
}
vedhav marked this conversation as resolved.
Show resolved Hide resolved
})
}
10 changes: 8 additions & 2 deletions R/teal_data_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#' `shiny` module server function; must only take `id` argument;
#' must return reactive expression containing `teal_data` object
#' @param label (`character(1)`) Label of the module.
#' @param once (`logical(1)`) Applicable only when used in the `data` argument of `init`.
#' If `TRUE`, the data module will be shown only once and will disappear after successful data loading.
#' App user will no longer be able to interact with this module anymore.
#' If `FALSE`, the data module can be reused multiple times.
#' App user will be able to interact and change the data output from the module multiple times.
#'
#' @return
#' `teal_data_module` returns an object of class `teal_data_module`.
Expand Down Expand Up @@ -54,7 +59,7 @@
#' @seealso [`teal.data::teal_data-class`], [teal.code::qenv()]
#'
#' @export
teal_data_module <- function(ui, server, label = "data module") {
teal_data_module <- function(ui, server, label = "data module", once = TRUE) {
checkmate::assert_function(ui, args = "id", nargs = 1)
checkmate::assert(
checkmate::check_function(server, args = "id", nargs = 1),
Expand All @@ -64,6 +69,7 @@ teal_data_module <- function(ui, server, label = "data module") {
structure(
list(ui = ui, server = server),
label = label,
class = "teal_data_module"
class = "teal_data_module",
once = once
)
}
47 changes: 21 additions & 26 deletions inst/js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,33 @@
resize is placed at end of functions
b/c in embedded apps it will throw errors that cause the function to exit early
*/
var filter_open = true;
const hideSidebar = () => {
$(".teal_secondary_col").fadeOut(1);
$(".teal_primary_col")
var filter_open = {};
const hideSidebar = (tabpanel_wrapper) => {
$(`#${tabpanel_wrapper} .teal_secondary_col`).fadeOut(1);
$(`#${tabpanel_wrapper} .teal_primary_col`)
.removeClass("col-sm-9")
.addClass("col-sm-12");
};
const showSidebar = () => {
$(".teal_primary_col")
const showSidebar = (tabpanel_wrapper) => {
$(`#${tabpanel_wrapper} .teal_primary_col`)
.removeClass("col-sm-12")
.addClass("col-sm-9");
$(".teal_secondary_col").fadeIn(650);
$(`#${tabpanel_wrapper} .teal_secondary_col`).fadeIn(650);
};
const toggleFilterPanel = () => {
if (filter_open && !$(".teal_secondary_col").is(':visible')) {
showSidebar();
const toggleFilterPanel = (tabpanel_wrapper) => {
console.log(`#${tabpanel_wrapper} .teal_secondary_col`);
console.log(filter_open[tabpanel_wrapper] === undefined);
vedhav marked this conversation as resolved.
Show resolved Hide resolved
if (filter_open[tabpanel_wrapper] === undefined) {
filter_open[tabpanel_wrapper] = true;
}
if (
filter_open[tabpanel_wrapper] &&
!$(`#${tabpanel_wrapper} .teal_secondary_col`).is(":visible")
) {
showSidebar(tabpanel_wrapper);
return;
}
filter_open = !filter_open;
if (filter_open) showSidebar();
else hideSidebar();
};

// Function to hide filter panel and disable the burger button
const handleNoActiveDatasets = () => {
$(".filter_hamburger").addClass("hidden");
$(".filter_manager_button").addClass("hidden");
hideSidebar();
filter_open[tabpanel_wrapper] = !filter_open[tabpanel_wrapper];
if (filter_open[tabpanel_wrapper]) showSidebar(tabpanel_wrapper);
else hideSidebar(tabpanel_wrapper);
};
// Function to show filter panel and enable the burger button
const handleActiveDatasetsPresent = () => {
$(".filter_hamburger").removeClass("hidden");
$(".filter_manager_button").removeClass("hidden");
if (filter_open) showSidebar();
}
3 changes: 3 additions & 0 deletions man/module_teal_module.Rd

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

8 changes: 7 additions & 1 deletion man/teal_data_module.Rd

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

Loading