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

[WIP] Add wrench icon #121

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
language: r
warnings_are_errors: true

r_binary_packages:
- Rcpp

notifications:
email:
on_success: change
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(box)
export(boxItem)
export(boxMenuOutput)
export(dashboardBody)
export(dashboardHeader)
export(dashboardPage)
Expand Down
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ shinydashboard 0.5.1.9000
--------------------------------------------------------------------------------
* Updated to AdminLTE 2.3.2 (1ee281b).

* Add wrench icon to the box-header (and a log more by using dropdown box-menu)

shinydashboard 0.5.1
--------------------------------------------------------------------------------

Expand Down
47 changes: 35 additions & 12 deletions R/boxes.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ infoBox <- function(title, value = NULL, subtitle = NULL,
#' the user to collapse the box.
#' @param collapsed If TRUE, start collapsed. This must be used with
#' \code{collapsible=TRUE}.
#' @param ... Contents of the box.
#' @param ... Contents of the box/boxItem.
#' @param boxMenu Adds a box menu consisting of \link{boxItem}.
#'
#' @family boxes
#'
Expand Down Expand Up @@ -250,7 +251,8 @@ infoBox <- function(title, value = NULL, subtitle = NULL,
#' @export
box <- function(..., title = NULL, footer = NULL, status = NULL,
solidHeader = FALSE, background = NULL, width = 6,
height = NULL, collapsible = FALSE, collapsed = FALSE) {
height = NULL, collapsible = FALSE, collapsed = FALSE,
boxMenu = NULL) {

boxClass <- "box"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After deep thinking:
Not so much sure if wrench= should be boolean. Rather something like tags$li =....
EDIT:see below

if (solidHeader || !is.null(background)) {
Expand Down Expand Up @@ -278,25 +280,26 @@ box <- function(..., title = NULL, footer = NULL, status = NULL,
titleTag <- h3(class = "box-title", title)
}

boxTools <- NULL
collapseTag <- NULL
if (collapsible) {
buttonStatus <- status %OR% "default"

if (collapsible) {
collapseIcon <- if (collapsed) "plus" else "minus"

collapseTag <- div(class = "box-tools pull-right",
tags$button(class = paste0("btn btn-box-tool"),
`data-widget` = "collapse",
shiny::icon(collapseIcon)
)
)
collapseTag <- tags$button(class = "btn btn-box-tool",
`data-widget` = "collapse",
shiny::icon(collapseIcon))
}

if (!is.null(collapseTag) || !is.null(boxMenu)) {
boxTools <- div(class = "box-tools pull-right", collapseTag, boxMenu)
}

headerTag <- NULL
if (!is.null(titleTag) || !is.null(collapseTag)) {
if (!is.null(titleTag) || !is.null(boxTools)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't boxTools always be non-NULL? I think the boxTools div should be created only if it's needed.

headerTag <- div(class = "box-header",
titleTag,
collapseTag
boxTools
)
}

Expand All @@ -310,6 +313,26 @@ box <- function(..., title = NULL, footer = NULL, status = NULL,
)
}

#' @inheritParams box
#' @param icon Default icon (if boxMenu is used) is wrench
#' @rdname box
#' @export
boxItem <- function(..., icon = shiny::icon("wrench")) {
listOfValues <- list(...)
# include each arg into <li> </li> tags
listOfLi <- lapply(listOfValues, tags$li)

tags$div(class = "btn-group",
tags$button(class = "btn btn-box-tool dropdown-toggle",
`type` = "button",
`data-toggle` = "dropdown",
icon),
tags$ul(class = "dropdown-menu",
`role` = "menu",
listOfLi)
)
}

#' Create a tabbed box
#'
#' @inheritParams shiny::tabsetPanel
Expand Down
2 changes: 1 addition & 1 deletion R/deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ addDeps <- function(x) {
}

dashboardDeps <- list(
htmlDependency("AdminLTE", "2.0.6",
htmlDependency("AdminLTE", "2.3.2",
c(file = system.file("AdminLTE", package = "shinydashboard")),
script = adminLTE_js,
stylesheet = adminLTE_css
Expand Down
39 changes: 27 additions & 12 deletions R/menuOutput.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ menuOutput <- function(outputId, tag = tags$li) {
}


#' Create a sidebar menu item output (client side)
#'
#' This is the UI-side function for creating a dynamic sidebar menu item.
#'
#' @inheritParams menuOutput
#' @family menu outputs
#' @seealso \code{\link{renderMenu}} for the corresponding server-side function
#' and examples, and \code{\link{menuItem}} for the corresponding function
#' for generating static sidebar menus.
#' @export
menuItemOutput <- function(outputId) {
menuOutput(outputId = outputId, tag = tags$li)
}


#' Create a dropdown menu output (client side)
#'
#' This is the UI-side function for creating a dynamic dropdown menu.
Expand All @@ -34,35 +49,35 @@ dropdownMenuOutput <- function(outputId) {
}


#' Create a sidebar menu output (client side)
#' Create a dropdown box-menu output (client side)
#'
#' This is the UI-side function for creating a dynamic sidebar menu.
#' This is the UI-side function for creating a dynamic dropdown box-menu.
#'
#' @inheritParams menuOutput
#' @family menu outputs
#' @seealso \code{\link{renderMenu}} for the corresponding server-side function
#' and examples, and \code{\link{sidebarMenu}} for the corresponding function
#' for generating static sidebar menus.
#' and examples, and \code{\link{dropdownMenu}} for the corresponding function
#' for generating static menus.
#' @export
sidebarMenuOutput <- function(outputId) {
menuOutput(outputId = outputId, tag = tags$ul)
boxMenuOutput <- function(outputId) {
menuOutput(outputId = outputId, tag = tags$div)
}

#' Create a sidebar menu item output (client side)

#' Create a sidebar menu output (client side)
#'
#' This is the UI-side function for creating a dynamic sidebar menu item.
#' This is the UI-side function for creating a dynamic sidebar menu.
#'
#' @inheritParams menuOutput
#' @family menu outputs
#' @seealso \code{\link{renderMenu}} for the corresponding server-side function
#' and examples, and \code{\link{menuItem}} for the corresponding function
#' and examples, and \code{\link{sidebarMenu}} for the corresponding function
#' for generating static sidebar menus.
#' @export
menuItemOutput <- function(outputId) {
menuOutput(outputId = outputId, tag = tags$li)
sidebarMenuOutput <- function(outputId) {
menuOutput(outputId = outputId, tag = tags$ul)
}


#' Create dynamic menu output (server side)
#'
#' @inheritParams shiny::renderUI
Expand Down
11 changes: 9 additions & 2 deletions man/box.Rd

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

24 changes: 24 additions & 0 deletions man/boxMenuOutput.Rd

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

6 changes: 3 additions & 3 deletions man/dropdownMenuOutput.Rd

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

3 changes: 2 additions & 1 deletion man/menuItemOutput.Rd

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

3 changes: 2 additions & 1 deletion man/menuOutput.Rd

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

3 changes: 2 additions & 1 deletion man/renderMenu.Rd

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

3 changes: 2 additions & 1 deletion man/sidebarMenuOutput.Rd

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

43 changes: 39 additions & 4 deletions tests-manual/box.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# A dashboard body with a row of infoBoxes and valueBoxes, and two rows of other boxes

library(shiny)
library(shinydashboard)

body <- dashboardBody(

# infoBoxes
Expand Down Expand Up @@ -39,10 +41,15 @@ body <- dashboardBody(
selectInput("progress", "Progress",
choices = c("0%" = 0, "20%" = 20, "40%" = 40, "60%" = 60, "80%" = 80,
"100%" = 100)
)
),
boxMenu = boxItem(a(href="https://www.bing.com", "bing it!",
style = "color: yellow", target = "_blank"),
downloadButton("svgdown", "download svg")),
collapsible = FALSE, collapsed = FALSE
),
box(title = "Histogram box title",
status = "warning", solidHeader = TRUE, collapsible = TRUE,
status = "info", solidHeader = TRUE, collapsible = T,
boxMenu = boxMenuOutput("menuWrench"),
plotOutput("plot", height = 250)
)
),
Expand Down Expand Up @@ -74,6 +81,25 @@ body <- dashboardBody(
)

server <- function(input, output) {
output$menuWrench <- renderMenu({
boxItem(p("some text", style="color: red"),
a(href="https://google.cz", "google czech", style = "color: red", target = "_blank"),
a(href="https://www.polygon.com", "polygon!", style = "color: yellow", target = "_blank"))
})

select_plot2 = function() {
hist(rnorm(input$orders))
}

output$svgdown <- downloadHandler(
filename <- "plot.svg",
content = function(file) {
svg(file)
select_plot2()
dev.off()
}
)

output$orderNum <- renderText({
prettyNum(input$orders, big.mark=",")
})
Expand Down Expand Up @@ -104,10 +130,10 @@ server <- function(input, output) {
p("Current status is: ", icon(iconName, lib = "glyphicon"))
})


output$plot <- renderPlot({
hist(rnorm(input$orders))
})

}
# A dashboard header with 3 dropdown menus
header <- dashboardHeader(
Expand Down Expand Up @@ -160,12 +186,21 @@ header <- dashboardHeader(
"Write documentation"
)
)

)

sidebar <- dashboardSidebar(
sidebarUserPanel(
"User Name",
subtitle = a(href = "#", icon("circle", class = "text-success"), "Online"),
image = "https://almsaeedstudio.com/themes/AdminLTE/dist/img/user2-160x160.jpg"
)
)

shinyApp(
ui = dashboardPage(
header,
dashboardSidebar(),
sidebar,
body
),
server = server
Expand Down