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

docs(pkgdown): Re-organize and add descriptions to reference index #842

Merged
merged 16 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
2 changes: 1 addition & 1 deletion R/fill.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' non-tag objects that have a [as.tags] method (e.g., htmlwidgets), they return
#' the "tagified" version of that object.
#'
#' @examplesIf interactive()
#' @examplesIf rlang::is_interactive()
#' library(shiny)
#' shinyApp(
#' page_fillable(
Expand Down
2 changes: 1 addition & 1 deletion R/input-switch.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#'
#' Create an on-off style switch control for specifying logical values.
#'
#' @examplesIf interactive()
#' @examplesIf rlang::is_interactive()
#' library(shiny)
#' library(bslib)
#'
Expand Down
2 changes: 1 addition & 1 deletion R/layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ layout_column_wrap <- function(
#'
#' @export
#' @seealso [breakpoints()] for more information on breakpoints.
#' @examplesIf interactive()
#' @examplesIf rlang::is_interactive()
#'
#'
#' x <- card("A simple card")
Expand Down
158 changes: 146 additions & 12 deletions R/page.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# page constructors from shiny so folks can create static
# pages without a shiny dependency.

#' Create a Bootstrap page
#' Modern Bootstrap page layouts
#'
#' These functions are small wrappers around shiny's page constructors (i.e.,
#' [shiny::fluidPage()], [shiny::navbarPage()], etc) that differ in two ways:
Expand All @@ -12,7 +12,10 @@
#' @inheritParams shiny::bootstrapPage
#' @param ... UI elements for the page. Named arguments become HTML attributes.
#' @param theme A [bslib::bs_theme()] object.
#' @seealso [page_sidebar()]
#'
#' @seealso Dashboard-style pages: [page_sidebar()], [page_navbar()],
#' [page_fillable()].
#'
#' @export
page <- function(..., title = NULL, theme = bs_theme(), lang = NULL) {
# Wrap ... in <body> since bootstrapPage() passes ... to tagList(),
Expand Down Expand Up @@ -51,8 +54,14 @@ page_fixed <- function(..., title = NULL, theme = bs_theme(), lang = NULL) {
)
}

#' @describeIn page `r lifecycle::badge("experimental")` A Bootstrap-based page
#' layout whose contents fill the full height and width of the browser window.
#' A screen-filling page layout
#'
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' A Bootstrap-based page layout whose contents fill the full height and width
#' of the browser window.
#'
#' @param padding Padding to use for the body. This can be a numeric vector
#' (which will be interpreted as pixels) or a character vector with valid CSS
#' lengths. The length can be between one and four. If one, then that value
Expand All @@ -65,8 +74,81 @@ page_fixed <- function(..., title = NULL, theme = bs_theme(), lang = NULL) {
#' height on mobile devices (i.e., narrow windows).
#' @param gap A [CSS length unit][htmltools::validateCssUnit()] defining the
#' `gap` (i.e., spacing) between elements provided to `...`.
#' @inheritParams page
#'
#' @seealso [card()] for wrapping outputs in the 'main' content area.
#' @seealso [value_box()] for highlighting values.
#' @seealso [layout_columns()] and [layout_column_wrap()] for laying out content
#' into rows and columns.
gadenbuie marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @examplesIf rlang::is_interactive()
#'
#' library(shiny)
#' library(ggplot2)
#'
#' ui <- page_fillable(
#' h1("Example", code("mtcars"), "dashboard"),
#' layout_columns(
#' card(
#' full_screen = TRUE,
#' card_header("Number of forward gears"),
#' plotOutput("gear")
#' ),
#' card(
#' full_screen = TRUE,
#' card_header("Number of carburetors"),
#' plotOutput("carb")
#' )
#' ),
#' card(
#' full_screen = TRUE,
#' card_header("Weight vs. Quarter Mile Time"),
#' layout_sidebar(
#' sidebar = sidebar(
#' varSelectInput("var_x", "Compare to qsec:", mtcars[-7], "wt"),
#' varSelectInput("color", "Color by:", mtcars[-7], "cyl"),
#' position = "right"
#' ),
#' plotOutput("var_vs_qsec")
#' )
#' )
#' )
#'
#' server <- function(input, output) {
#' for (var in c("cyl", "vs", "am", "gear", "carb")) {
#' mtcars[[var]] <- as.factor(mtcars[[var]])
#' }
#'
#' output$gear <- renderPlot({
#' ggplot(mtcars, aes(gear)) + geom_bar()
#' })
#'
#' output$carb <- renderPlot({
#' ggplot(mtcars, aes(carb)) + geom_bar()
#' })
#'
#' output$var_vs_qsec <- renderPlot({
#' req(input$var_x, input$color)
#'
#' ggplot(mtcars) +
#' aes(y = qsec, x = !!input$var_x, color = !!input$color) +
#' geom_point()
#' })
#' }
#'
#' shinyApp(ui, server)
Comment on lines +97 to +150
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice! Maybe once shiny::runExample() gets an extension point this would be a good candidate for an example?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks and yeah, good idea!

#'
#'
#' @export
page_fillable <- function(..., padding = NULL, gap = NULL, fillable_mobile = FALSE, title = NULL, theme = bs_theme(), lang = NULL) {
page_fillable <- function(
...,
padding = NULL,
gap = NULL,
fillable_mobile = FALSE,
title = NULL,
theme = bs_theme(),
lang = NULL
) {
page(
title = title,
theme = theme,
Expand Down Expand Up @@ -96,13 +178,14 @@ validateCssPadding <- function(padding = NULL) {
#'
#' Create a dashboard layout with a full-bleed header (`title`) and [sidebar()].
#'
#' @inheritParams layout_sidebar
#' @inheritParams page_fillable
#' @param ... UI elements to display in the 'main' content area (i.e., next to
#' the `sidebar`). These arguments are passed to `layout_sidebar()`, which has
#' more details.
#' @param title A string, number, or [htmltools::tag()] child to display as the
#' title (just above the `sidebar`).
#' @inheritParams layout_sidebar
#' @inheritParams page_fillable
#' @inheritParams page_navbar
#'
gadenbuie marked this conversation as resolved.
Show resolved Hide resolved
#' @export
#' @seealso [layout_sidebar()] for 'floating' sidebar layouts.
gadenbuie marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -135,8 +218,16 @@ validateCssPadding <- function(padding = NULL) {
#'
#' shinyApp(ui, server)
#'
page_sidebar <- function(..., sidebar = NULL, title = NULL, fillable = TRUE, fillable_mobile = FALSE, theme = bs_theme(), window_title = NA, lang = NULL) {

page_sidebar <- function(
...,
sidebar = NULL,
title = NULL,
fillable = TRUE,
fillable_mobile = FALSE,
theme = bs_theme(),
window_title = NA,
lang = NULL
) {
if (rlang::is_bare_character(title) || rlang::is_bare_numeric(title)) {
title <- h1(title, class = "bslib-page-title")
}
Expand All @@ -161,16 +252,59 @@ page_sidebar <- function(..., sidebar = NULL, title = NULL, fillable = TRUE, fil
}


#' @rdname page
#' @inheritParams navset_bar
#' @seealso [shiny::navbarPage()]
#' Multi-page app with a top navigation bar
#'
#' @description
#' `page_navbar()` provides a full-screen app with a navigation bar that behaves
#' like a multi-page app (but is really a single-page app).
cpsievert marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @param fillable_mobile Whether or not `fillable` pages should fill the viewport's
#' height on mobile devices (i.e., narrow windows).
#' @param underline Whether or not to add underline styling to page links when
#' active or focused.
#' @param window_title the browser window title. The default value, `NA`, means
#' to use any character strings that appear in `title` (if none are found, the
#' host URL of the page is displayed by default).
#' @inheritParams navset_bar
#' @inheritParams page
#'
#' @seealso [shiny::navbarPage()]
gadenbuie marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @examplesIf rlang::is_interactive()
#' library(shiny)
#' library(bslib)
#'
#' link_shiny <- tags$a(
#' shiny::icon("github"), "Shiny",
#' href = "https://github.com/rstudio/shiny",
#' target = "_blank"
#' )
#' link_posit <- tags$a(
#' shiny::icon("r-project"), "Posit",
#' href = "https://posit.co",
#' target = "_blank"
#' )
#'
#' ui <- page_navbar(
#' title = "My App",
#' bg = "#0062cc",
#' underline = TRUE,
gadenbuie marked this conversation as resolved.
Show resolved Hide resolved
#' nav_panel(title = "One", p("First page content.")),
#' nav_panel(title = "Two", p("Second page content.")),
#' nav_spacer(),
#' nav_item(link_shiny),
#' nav_menu(
#' title = "Other links",
#' align = "right",
#' nav_panel("Three", p("Third page content.")),
#' nav_item(link_posit)
#' )
gadenbuie marked this conversation as resolved.
Show resolved Hide resolved
#' )
#'
#' server <- function(...) { } # not used in this example
#'
#' shinyApp(ui, server)
#'
#' @export
page_navbar <- function(
...,
Expand Down
3 changes: 2 additions & 1 deletion R/popover.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
#' @references <https://getbootstrap.com/docs/5.3/components/popovers/>
#' @export
#' @seealso [tooltip()]
#' @examplesIf interactive()
#'
#' @examplesIf rlang::is_interactive()
#'
#' popover(
#' shiny::actionButton("btn", "A button"),
Expand Down
2 changes: 1 addition & 1 deletion R/tooltip.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#' @references <https://getbootstrap.com/docs/5.3/components/tooltips/>
#' @export
#' @seealso [popover()]
#' @examplesIf interactive()
#' @examplesIf rlang::is_interactive()
#'
#' tooltip(
#' shiny::actionButton("btn", "A button"),
Expand Down
24 changes: 11 additions & 13 deletions R/value-box.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,19 @@
#' @inheritParams card
#' @param theme_color `r lifecycle::badge("deprecated")` Use `theme` instead.
#'
#' @examples
#' @examplesIf rlang::is_interactive()
#' library(htmltools)
#'
#' if (interactive()) {
#' value_box(
#' "KPI Title",
#' h1(HTML("$1 <i>Billion</i> Dollars")),
#' span(
#' bsicons::bs_icon("arrow-up"),
#' " 30% VS PREVIOUS 30 DAYS"
#' ),
#' showcase = bsicons::bs_icon("piggy-bank"),
#' theme = "success"
#' )
#' }
#' value_box(
#' "KPI Title",
#' h1(HTML("$1 <i>Billion</i> Dollars")),
#' span(
#' bsicons::bs_icon("arrow-up"),
#' " 30% VS PREVIOUS 30 DAYS"
#' ),
#' showcase = bsicons::bs_icon("piggy-bank"),
#' theme = "success"
#' )
#'
#' @seealso [card()]
#' @export
Expand Down
Loading
Loading