Skip to content

Commit

Permalink
fix tabs, remove maggritr dep, R CMD clean
Browse files Browse the repository at this point in the history
  • Loading branch information
DivadNojnarg committed Jun 23, 2024
1 parent ecfc4f8 commit da148ad
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 84 deletions.
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ Description: This template is made for people having nostalgic feelings about fl
Less distraction for more productivity!
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
URL: https://github.com/RinteRface/shiny386
BugReports: https://github.com/RinteRface/shiny386/issues
Imports:
htmltools (>= 0.5.2),
shiny,
magrittr,
httpuv
httpuv,
bslib
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(badge_386)
export(button_386)
export(card_386)
Expand Down Expand Up @@ -47,4 +46,3 @@ export(validate_progress_value)
export(validate_status)
import(htmltools)
import(shiny)
importFrom(magrittr,"%>%")
44 changes: 22 additions & 22 deletions R/deps.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
bs4_deps <- htmltools::htmlDependency(
name = "Bootstrap",
version = "4.4.1",
src = c(file = "bootstrap-4.4.1"),
package = "shiny386",
script = c(
"js/bootstrap.bundle.js",
"js/custom.js",
"js/progress_handler.js",
"js/toast_handler.js",
"js/radioButtonsBinding.js",
"js/tabsetPanelBinding.js",
"js/dropdownInputBinding.js"
),
stylesheet = c(
"css/bootstrap.min.css",
"css/custom.css"
)
)


#' Create shiny386 dependencies
#'
#' Add all necessary dependencies so that shiny386 renders well
Expand All @@ -27,5 +6,26 @@ bs4_deps <- htmltools::htmlDependency(
#' @export
#' @seealso \link{page_386}.
use_bs4_deps <- function(tag) {
tagList(tag, bs4_deps)
tagList(
tag,
htmltools::htmlDependency(
name = "Bootstrap",
version = "4.4.1",
src = c(file = "bootstrap-4.4.1"),
package = "shiny386",
script = c(
"js/bootstrap.bundle.js",
"js/custom.js",
"js/progress_handler.js",
"js/toast_handler.js",
"js/radioButtonsBinding.js",
"js/tabsetPanelBinding.js",
"js/dropdownInputBinding.js"
),
stylesheet = c(
"css/bootstrap.min.css",
"css/custom.css"
)
)
)
}
57 changes: 26 additions & 31 deletions R/layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@ page_386 <- function(..., title = NULL) {
tags$meta(`http-equiv` = "X-UA-Compatible", content = "IE=edge")
),
# body
tags$body(
div(
class = "container",
...
use_bs4_deps(
tags$body(
div(
class = "container",
...
)
)
) %>% use_bs4_deps()
)
)
}



#' Create a Bootstrap 386 tabset panel
#' @inheritParams shiny::tabsetPanel
#' @param position Tabs position.
#' @export
#' @examples
#' if (interactive()) {
Expand Down Expand Up @@ -70,30 +73,22 @@ tabset_panel_386 <- function(..., id = NULL, selected = NULL,
)

# Some edit below since Bootstrap 4 significantly changed the layout
nav_items <- temp_tabset$children[[1]]$children[[1]]
found_active <- FALSE
bs4_nav_items <- lapply(nav_items, function(x) {
if (!is.null(x$attribs$class)) {
if (grep(x = x$attribs$class, pattern = "active")) {
x$attribs$class <- NULL
found_active <- TRUE
htmltools::tagQuery(temp_tabset)$
find("li")$
each(
function(x, i) {
# replace text
current_tab <- x$children[[1]]$attribs$`data-value`
x$attribs$class <- "nav-item"
x$children[[1]]$attribs$class <- if (selected == current_tab) {
"nav-link active"
} else {
"nav-link"
}
x
}
}
x$attribs$class <- if (is.null(x$attribs$class)) {
"nav-item"
} else {
paste("nav-item", x$attribs$class)
}
x$children[[1]]$attribs$class <- if (found_active) {
"nav-link active"
} else {
"nav-link"
}
x
})

temp_tabset$children[[1]]$children[[1]] <- bs4_nav_items
temp_tabset
)$
allTags()
}


Expand Down Expand Up @@ -205,9 +200,9 @@ update_tabset_panel_386 <- shiny::updateTabsetPanel
#' shinyApp(ui, server)
#' }
navbar_page_386 <- function (title, ..., id = NULL, selected = NULL,
position = c("static-top", "fixed-top", "fixed-bottom"),
header = NULL, footer = NULL, inverse = FALSE,
windowTitle = title) {
position = c("static-top", "fixed-top", "fixed-bottom"),
header = NULL, footer = NULL, inverse = FALSE,
windowTitle = title) {
pageTitle <- title
navbarClass <- "navbar navbar-expand-lg navbar-dark bg-primary"
position <- match.arg(position)
Expand Down
2 changes: 1 addition & 1 deletion R/user-feedback.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ toast_386 <- function(id, title = NULL, subtitle = NULL, ..., img = NULL) {
`data-toggle` = "toast"
)

toast_wrapper %>% tagAppendChildren(toast_header, toast_body)
tagAppendChildren(toast_wrapper, toast_header, toast_body)
}


Expand Down
11 changes: 0 additions & 11 deletions R/utils-pipe.R

This file was deleted.

5 changes: 3 additions & 2 deletions R/utils-shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ create_checkbox_tag <- function(inputId, label, value = FALSE, width = NULL,
)

if (!is.null(value) && value) {
input_tag <- input_tag %>% tagAppendAttributes(checked = "checked")
input_tag <- tagAppendAttributes(input_tag, checked = "checked")
}

input_wrapper <- tags$div(
Expand All @@ -37,7 +37,8 @@ create_checkbox_tag <- function(inputId, label, value = FALSE, width = NULL,
}
)

input_wrapper %>% tagAppendChildren(
tagAppendChildren(
input_wrapper,
input_tag,
tags$label(class = "custom-control-label", `for` = inputId, label)
)
Expand Down
12 changes: 0 additions & 12 deletions man/pipe.Rd

This file was deleted.

2 changes: 2 additions & 0 deletions man/tabset_panel_386.Rd

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

0 comments on commit da148ad

Please sign in to comment.