Skip to content

Commit

Permalink
added useShinydashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed May 22, 2018
1 parent e137921 commit a01d425
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export(updateSearchInput)
export(updateSliderTextInput)
export(updateSpectrumInput)
export(updateSwitchInput)
export(useShinydashboard)
export(useSweetAlert)
export(wNumbFormat)
importFrom(grDevices,col2rgb)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ shinyWidgets 0.4.2.900
* New function `downloadBttn`, a `downloadButton` with custom appearance.
* New widget `airDatepickerInput`, to select single, multiple and range of dates. You can also select time. And two shortcuts to select months or years.
* New function to add spinners when outputs are recalculating.
* New function `useShinydashboard` to use functions from 'shinydashboard' into a classic 'shiny' app, specifically `valueBox`, `infoBox` and `box`.


shinyWidgets 0.4.2
Expand Down
113 changes: 113 additions & 0 deletions R/useShinydashboard.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

#' Use 'shinydashboard' in 'shiny'
#'
#' Allow to use functions from 'shinydashboard' into a classic 'shiny' app,
#' specifically \code{valueBox}, \code{infoBox} and \code{box}.
#'
#' @export
#'
#' @importFrom htmltools findDependencies attachDependencies
#'
#' @examples
#' \dontrun{
#'
#' if (interactive()) {
#'
#' library(shiny)
#' library(shinydashboard)
#'
#' # example taken from ?box
#'
#' ui <- fluidPage(
#' tags$h2("Classic shiny"),
#'
#' # use this in non shinydashboard app
#' useShinydashboard(),
#' # -----------------
#'
#' # infoBoxes
#' fluidRow(
#' infoBox(
#' "Orders", uiOutput("orderNum2"), "Subtitle", icon = icon("credit-card")
#' ),
#' infoBox(
#' "Approval Rating", "60%", icon = icon("line-chart"), color = "green",
#' fill = TRUE
#' ),
#' infoBox(
#' "Progress", uiOutput("progress2"), icon = icon("users"), color = "purple"
#' )
#' ),
#'
#' # valueBoxes
#' fluidRow(
#' valueBox(
#' uiOutput("orderNum"), "New Orders", icon = icon("credit-card"),
#' href = "http://google.com"
#' ),
#' valueBox(
#' tagList("60", tags$sup(style="font-size: 20px", "%")),
#' "Approval Rating", icon = icon("line-chart"), color = "green"
#' ),
#' valueBox(
#' htmlOutput("progress"), "Progress", icon = icon("users"), color = "purple"
#' )
#' ),
#'
#' # Boxes
#' fluidRow(
#' box(status = "primary",
#' sliderInput("orders", "Orders", min = 1, max = 2000, value = 650),
#' selectInput("progress", "Progress",
#' choices = c("0%" = 0, "20%" = 20, "40%" = 40, "60%" = 60, "80%" = 80,
#' "100%" = 100)
#' )
#' ),
#' box(title = "Histogram box title",
#' status = "warning", solidHeader = TRUE, collapsible = TRUE,
#' plotOutput("plot", height = 250)
#' )
#' )
#' )
#'
#' server <- function(input, output, session) {
#'
#' output$orderNum <- renderText({
#' prettyNum(input$orders, big.mark=",")
#' })
#'
#' output$orderNum2 <- renderText({
#' prettyNum(input$orders, big.mark=",")
#' })
#'
#' output$progress <- renderUI({
#' tagList(input$progress, tags$sup(style="font-size: 20px", "%"))
#' })
#'
#' output$progress2 <- renderUI({
#' paste0(input$progress, "%")
#' })
#'
#'
#' output$plot <- renderPlot({
#' hist(rnorm(input$orders))
#' })
#'
#' }
#'
#' shinyApp(ui, server)
#'
#' }
#'
#' }
useShinydashboard <- function() {
if (!requireNamespace(package = "shinydashboard"))
message("Package 'shinydashboard' is required to run this function")
deps <- findDependencies(shinydashboard::dashboardPage(
header = shinydashboard::dashboardHeader(),
sidebar = shinydashboard::dashboardSidebar(),
body = shinydashboard::dashboardBody()
))
attachDependencies(tags$div(), value = deps)
}

105 changes: 105 additions & 0 deletions man/useShinydashboard.Rd

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

0 comments on commit a01d425

Please sign in to comment.