From 81ca9d9f29fcb9f01f468b0a2018d53169aa6a30 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 29 Aug 2019 08:00:40 -0500 Subject: [PATCH 1/3] Co-locate all sidebarLayout() functions --- R/bootstrap-layout.R | 54 ++++++++++++++++++++++++++++++++++++++++++++ R/bootstrap.R | 53 ------------------------------------------- man/mainPanel.Rd | 2 +- man/sidebarPanel.Rd | 2 +- 4 files changed, 56 insertions(+), 55 deletions(-) diff --git a/R/bootstrap-layout.R b/R/bootstrap-layout.R index 90233d41a..87bf76fa2 100644 --- a/R/bootstrap-layout.R +++ b/R/bootstrap-layout.R @@ -337,6 +337,60 @@ sidebarLayout <- function(sidebarPanel, fixedRow(firstPanel, secondPanel) } +#' Create a sidebar panel +#' +#' Create a sidebar panel containing input controls that can in turn be passed +#' to [sidebarLayout()]. +#' +#' @param ... UI elements to include on the sidebar +#' @param width The width of the sidebar. For fluid layouts this is out of 12 +#' total units; for fixed layouts it is out of whatever the width of the +#' sidebar's parent column is. +#' @return A sidebar that can be passed to [sidebarLayout()] +#' +#' @examples +#' # Sidebar with controls to select a dataset and specify +#' # the number of observations to view +#' sidebarPanel( +#' selectInput("dataset", "Choose a dataset:", +#' choices = c("rock", "pressure", "cars")), +#' +#' numericInput("obs", "Observations:", 10) +#' ) +#' @export +sidebarPanel <- function(..., width = 4) { + div(class=paste0("col-sm-", width), + tags$form(class="well", + ... + ) + ) +} + +#' Create a main panel +#' +#' Create a main panel containing output elements that can in turn be passed to +#' [sidebarLayout()]. +#' +#' @param ... Output elements to include in the main panel +#' @param width The width of the main panel. For fluid layouts this is out of 12 +#' total units; for fixed layouts it is out of whatever the width of the main +#' panel's parent column is. +#' @return A main panel that can be passed to [sidebarLayout()]. +#' +#' @examples +#' # Show the caption and plot of the requested variable against mpg +#' mainPanel( +#' h3(textOutput("caption")), +#' plotOutput("mpgPlot") +#' ) +#' @export +mainPanel <- function(..., width = 8) { + div(class=paste0("col-sm-", width), + ... + ) +} + + #' Lay out UI elements vertically #' #' Create a container that includes one or more rows of content (each element diff --git a/R/bootstrap.R b/R/bootstrap.R index 08111e38d..b87561016 100644 --- a/R/bootstrap.R +++ b/R/bootstrap.R @@ -441,59 +441,6 @@ wellPanel <- function(...) { div(class="well", ...) } -#' Create a sidebar panel -#' -#' Create a sidebar panel containing input controls that can in turn be passed -#' to [sidebarLayout()]. -#' -#' @param ... UI elements to include on the sidebar -#' @param width The width of the sidebar. For fluid layouts this is out of 12 -#' total units; for fixed layouts it is out of whatever the width of the -#' sidebar's parent column is. -#' @return A sidebar that can be passed to [sidebarLayout()] -#' -#' @examples -#' # Sidebar with controls to select a dataset and specify -#' # the number of observations to view -#' sidebarPanel( -#' selectInput("dataset", "Choose a dataset:", -#' choices = c("rock", "pressure", "cars")), -#' -#' numericInput("obs", "Observations:", 10) -#' ) -#' @export -sidebarPanel <- function(..., width = 4) { - div(class=paste0("col-sm-", width), - tags$form(class="well", - ... - ) - ) -} - -#' Create a main panel -#' -#' Create a main panel containing output elements that can in turn be passed to -#' [sidebarLayout()]. -#' -#' @param ... Output elements to include in the main panel -#' @param width The width of the main panel. For fluid layouts this is out of 12 -#' total units; for fixed layouts it is out of whatever the width of the main -#' panel's parent column is. -#' @return A main panel that can be passed to [sidebarLayout()]. -#' -#' @examples -#' # Show the caption and plot of the requested variable against mpg -#' mainPanel( -#' h3(textOutput("caption")), -#' plotOutput("mpgPlot") -#' ) -#' @export -mainPanel <- function(..., width = 8) { - div(class=paste0("col-sm-", width), - ... - ) -} - #' Conditional Panel #' #' Creates a panel that is visible or not, depending on the value of a diff --git a/man/mainPanel.Rd b/man/mainPanel.Rd index 5c0b6687e..26438ac47 100644 --- a/man/mainPanel.Rd +++ b/man/mainPanel.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/bootstrap.R +% Please edit documentation in R/bootstrap-layout.R \name{mainPanel} \alias{mainPanel} \title{Create a main panel} diff --git a/man/sidebarPanel.Rd b/man/sidebarPanel.Rd index 5feadbf4d..273e73b69 100644 --- a/man/sidebarPanel.Rd +++ b/man/sidebarPanel.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/bootstrap.R +% Please edit documentation in R/bootstrap-layout.R \name{sidebarPanel} \alias{sidebarPanel} \title{Create a sidebar panel} From 98ca820ab11be0d4f3919c264469c3d6c02b1c0a Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 29 Aug 2019 08:09:22 -0500 Subject: [PATCH 2/3] Document sidebarPanel() and mainPanel() with sidebarLayout() --- R/bootstrap-layout.R | 55 +++++++++-------------------------------- inst/staticdocs/index.r | 2 -- man/mainPanel.Rd | 29 ---------------------- man/sidebarLayout.Rd | 23 +++++++++++++---- man/sidebarPanel.Rd | 32 ------------------------ 5 files changed, 30 insertions(+), 111 deletions(-) delete mode 100644 man/mainPanel.Rd delete mode 100644 man/sidebarPanel.Rd diff --git a/R/bootstrap-layout.R b/R/bootstrap-layout.R index 87bf76fa2..f68b44239 100644 --- a/R/bootstrap-layout.R +++ b/R/bootstrap-layout.R @@ -263,16 +263,21 @@ titlePanel <- function(title, windowTitle=title) { #' Layout a sidebar and main area #' -#' Create a layout with a sidebar and main area. The sidebar is displayed with a -#' distinct background color and typically contains input controls. The main +#' Create a layout (`sidebarLayout()`) with a sidebar (`sidebarPanel()`) and +#' main area (`mainPanel()`). The sidebar is displayed with a distinct +#' background color and typically contains input controls. The main #' area occupies 2/3 of the horizontal width and typically contains outputs. #' -#' @param sidebarPanel The [sidebarPanel] containing input controls -#' @param mainPanel The [mainPanel] containing outputs +#' @param sidebarPanel The `sidebarPanel()` containing input controls. +#' @param mainPanel The `mainPanel()` containing outputs. #' @param position The position of the sidebar relative to the main area ("left" -#' or "right") +#' or "right"). #' @param fluid `TRUE` to use fluid layout; `FALSE` to use fixed #' layout. +#' @param width The width of the sidebar and main panel. By default, the +#' sidebar takes up 1/3 of the width, and the main panel 2/3. The total +#' width must be 12 or less. +#' @param ... Output elements to include in the sidebar/main panel. #' #' @examples #' ## Only run examples in interactive R sessions @@ -337,27 +342,8 @@ sidebarLayout <- function(sidebarPanel, fixedRow(firstPanel, secondPanel) } -#' Create a sidebar panel -#' -#' Create a sidebar panel containing input controls that can in turn be passed -#' to [sidebarLayout()]. -#' -#' @param ... UI elements to include on the sidebar -#' @param width The width of the sidebar. For fluid layouts this is out of 12 -#' total units; for fixed layouts it is out of whatever the width of the -#' sidebar's parent column is. -#' @return A sidebar that can be passed to [sidebarLayout()] -#' -#' @examples -#' # Sidebar with controls to select a dataset and specify -#' # the number of observations to view -#' sidebarPanel( -#' selectInput("dataset", "Choose a dataset:", -#' choices = c("rock", "pressure", "cars")), -#' -#' numericInput("obs", "Observations:", 10) -#' ) #' @export +#' @rdname sidebarLayout sidebarPanel <- function(..., width = 4) { div(class=paste0("col-sm-", width), tags$form(class="well", @@ -366,31 +352,14 @@ sidebarPanel <- function(..., width = 4) { ) } -#' Create a main panel -#' -#' Create a main panel containing output elements that can in turn be passed to -#' [sidebarLayout()]. -#' -#' @param ... Output elements to include in the main panel -#' @param width The width of the main panel. For fluid layouts this is out of 12 -#' total units; for fixed layouts it is out of whatever the width of the main -#' panel's parent column is. -#' @return A main panel that can be passed to [sidebarLayout()]. -#' -#' @examples -#' # Show the caption and plot of the requested variable against mpg -#' mainPanel( -#' h3(textOutput("caption")), -#' plotOutput("mpgPlot") -#' ) #' @export +#' @rdname sidebarLayout mainPanel <- function(..., width = 8) { div(class=paste0("col-sm-", width), ... ) } - #' Lay out UI elements vertically #' #' Create a container that includes one or more rows of content (each element diff --git a/inst/staticdocs/index.r b/inst/staticdocs/index.r index e5d3ffa79..710ce73a5 100644 --- a/inst/staticdocs/index.r +++ b/inst/staticdocs/index.r @@ -12,12 +12,10 @@ sd_section("UI Layout", "headerPanel", "helpText", "icon", - "mainPanel", "navbarPage", "navlistPanel", "pageWithSidebar", "sidebarLayout", - "sidebarPanel", "tabPanel", "tabsetPanel", "titlePanel", diff --git a/man/mainPanel.Rd b/man/mainPanel.Rd deleted file mode 100644 index 26438ac47..000000000 --- a/man/mainPanel.Rd +++ /dev/null @@ -1,29 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/bootstrap-layout.R -\name{mainPanel} -\alias{mainPanel} -\title{Create a main panel} -\usage{ -mainPanel(..., width = 8) -} -\arguments{ -\item{...}{Output elements to include in the main panel} - -\item{width}{The width of the main panel. For fluid layouts this is out of 12 -total units; for fixed layouts it is out of whatever the width of the main -panel's parent column is.} -} -\value{ -A main panel that can be passed to \code{\link[=sidebarLayout]{sidebarLayout()}}. -} -\description{ -Create a main panel containing output elements that can in turn be passed to -\code{\link[=sidebarLayout]{sidebarLayout()}}. -} -\examples{ -# Show the caption and plot of the requested variable against mpg -mainPanel( - h3(textOutput("caption")), - plotOutput("mpgPlot") -) -} diff --git a/man/sidebarLayout.Rd b/man/sidebarLayout.Rd index da416587d..bc5235656 100644 --- a/man/sidebarLayout.Rd +++ b/man/sidebarLayout.Rd @@ -2,25 +2,38 @@ % Please edit documentation in R/bootstrap-layout.R \name{sidebarLayout} \alias{sidebarLayout} +\alias{sidebarPanel} +\alias{mainPanel} \title{Layout a sidebar and main area} \usage{ sidebarLayout(sidebarPanel, mainPanel, position = c("left", "right"), fluid = TRUE) + +sidebarPanel(..., width = 4) + +mainPanel(..., width = 8) } \arguments{ -\item{sidebarPanel}{The \link{sidebarPanel} containing input controls} +\item{sidebarPanel}{The \code{sidebarPanel()} containing input controls.} -\item{mainPanel}{The \link{mainPanel} containing outputs} +\item{mainPanel}{The \code{mainPanel()} containing outputs.} \item{position}{The position of the sidebar relative to the main area ("left" -or "right")} +or "right").} \item{fluid}{\code{TRUE} to use fluid layout; \code{FALSE} to use fixed layout.} + +\item{...}{Output elements to include in the sidebar/main panel.} + +\item{width}{The width of the sidebar and main panel. By default, the +sidebar takes up 1/3 of the width, and the main panel 2/3. The total +width must be 12 or less.} } \description{ -Create a layout with a sidebar and main area. The sidebar is displayed with a -distinct background color and typically contains input controls. The main +Create a layout (\code{sidebarLayout()}) with a sidebar (\code{sidebarPanel()}) and +main area (\code{mainPanel()}). The sidebar is displayed with a distinct +background color and typically contains input controls. The main area occupies 2/3 of the horizontal width and typically contains outputs. } \examples{ diff --git a/man/sidebarPanel.Rd b/man/sidebarPanel.Rd deleted file mode 100644 index 273e73b69..000000000 --- a/man/sidebarPanel.Rd +++ /dev/null @@ -1,32 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/bootstrap-layout.R -\name{sidebarPanel} -\alias{sidebarPanel} -\title{Create a sidebar panel} -\usage{ -sidebarPanel(..., width = 4) -} -\arguments{ -\item{...}{UI elements to include on the sidebar} - -\item{width}{The width of the sidebar. For fluid layouts this is out of 12 -total units; for fixed layouts it is out of whatever the width of the -sidebar's parent column is.} -} -\value{ -A sidebar that can be passed to \code{\link[=sidebarLayout]{sidebarLayout()}} -} -\description{ -Create a sidebar panel containing input controls that can in turn be passed -to \code{\link[=sidebarLayout]{sidebarLayout()}}. -} -\examples{ -# Sidebar with controls to select a dataset and specify -# the number of observations to view -sidebarPanel( - selectInput("dataset", "Choose a dataset:", - choices = c("rock", "pressure", "cars")), - - numericInput("obs", "Observations:", 10) -) -} From 0813789e2ad5febee23d3fc961662e5a582e6e61 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 29 Aug 2019 08:15:19 -0500 Subject: [PATCH 3/3] Cross-link tabPanel() to navbarPage() --- R/bootstrap.R | 3 ++- man/tabPanel.Rd | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/R/bootstrap.R b/R/bootstrap.R index b87561016..e7a7aec56 100644 --- a/R/bootstrap.R +++ b/R/bootstrap.R @@ -536,7 +536,8 @@ helpText <- function(...) { #' Create a tab panel #' -#' Create a tab panel that can be included within a [tabsetPanel()]. +#' Create a tab panel that can be included within a [tabsetPanel()] or +#' a [navbarPage()]. #' #' @param title Display title for tab #' @param ... UI elements to include within the tab diff --git a/man/tabPanel.Rd b/man/tabPanel.Rd index b4cd78fd5..c21213673 100644 --- a/man/tabPanel.Rd +++ b/man/tabPanel.Rd @@ -22,7 +22,8 @@ valid when using a \code{tabPanel} within a \code{\link[=navbarPage]{navbarPage( A tab that can be passed to \code{\link[=tabsetPanel]{tabsetPanel()}} } \description{ -Create a tab panel that can be included within a \code{\link[=tabsetPanel]{tabsetPanel()}}. +Create a tab panel that can be included within a \code{\link[=tabsetPanel]{tabsetPanel()}} or +a \code{\link[=navbarPage]{navbarPage()}}. } \examples{ # Show a tabset that includes a plot, summary, and