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

feat(build-a-box): Add example value box builder app #790

Merged
merged 66 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
8c4e1b9
feat(build-a-box): Add example value box builder app
gadenbuie Sep 5, 2023
fd38020
Update website deps (GitHub Action)
gadenbuie Sep 7, 2023
193a286
feat(build-a-box): Add copy to clipboard button
gadenbuie Sep 7, 2023
4d3c2c3
chore: Remove debug code
gadenbuie Sep 7, 2023
6e52864
refactor: `code_modal()`
gadenbuie Sep 7, 2023
4e3d688
feat: Remove `extra` args from `value_box()` call if `NULL`
gadenbuie Sep 7, 2023
79be900
refactor: Only value box foreground color is reported back to server
gadenbuie Sep 7, 2023
7af830d
chore: use monospace for extra info
gadenbuie Sep 7, 2023
805146b
TEMP: deploy shiny apps (REVERT BEFORE MERGING)
gadenbuie Sep 7, 2023
5d4e54c
Resave data (GitHub Action)
gadenbuie Sep 7, 2023
cae48a3
ci: Deploy anything with a `deploy.R`
gadenbuie Sep 7, 2023
de99f41
chore: remove unused js file
gadenbuie Sep 7, 2023
0ada949
fix: clipboard fallback behavior
gadenbuie Sep 7, 2023
8dd8603
feat: global controls
gadenbuie Sep 8, 2023
da3723f
chore: Enable themer on the demo site
gadenbuie Sep 8, 2023
e692d9d
refactor: Move global settings into module
gadenbuie Sep 8, 2023
c7c60bf
ci: shinyapps.io doesn't support `envVars`
gadenbuie Sep 8, 2023
91b5da3
cI: Register additional public shinyapps.io account
gadenbuie Sep 8, 2023
9e34a32
ci: use latest {rsconnect}
gadenbuie Sep 8, 2023
079bcd7
ci: Don't need to make account name secret
gadenbuie Sep 8, 2023
f1fa393
ci: Deploy build-a-box to bslib.shinyapps.io
gadenbuie Sep 8, 2023
f8908ed
Merged origin/main into feat/box-builder
gadenbuie Sep 8, 2023
e258656
feat: Add dark mode switcher
gadenbuie Sep 8, 2023
17f6a0b
fix: incomplete reset of file
gadenbuie Sep 8, 2023
492b691
chore: Don't need clipboard.min.js at all
gadenbuie Sep 8, 2023
8d77f40
fix: prefix call to `css()`
gadenbuie Sep 8, 2023
6f6b818
fix: order of value boxes in the code
gadenbuie Sep 8, 2023
3a24f15
refactor: Move code-modal.js to new file
gadenbuie Sep 8, 2023
edd19d1
chore: remove unneeded gap
gadenbuie Sep 8, 2023
4b0a99a
chore: use `bs_theme() |> bs_add_rules()`
gadenbuie Sep 8, 2023
9af4808
feat: Add footer
gadenbuie Sep 8, 2023
1e22827
feat: Add a tooltip with info about value_box()
gadenbuie Sep 8, 2023
7048996
Resave distributed files (GitHub Action)
gadenbuie Sep 8, 2023
892502a
chore: add title to button
gadenbuie Sep 8, 2023
672a5b0
Resave distributed files (GitHub Action)
gadenbuie Sep 8, 2023
e1c27a7
feat: random theme when changing the global theme style
gadenbuie Sep 8, 2023
67c642a
chore: tweak wording of "Use custom colors" and "Include showcase"
gadenbuie Sep 8, 2023
6ba9d2a
chore: Use radioButtons in global settings too
gadenbuie Sep 8, 2023
c58dc4e
Resave distributed files (GitHub Action)
gadenbuie Sep 8, 2023
d327273
chore: Add {commonmark} to deploy dependencies
gadenbuie Sep 11, 2023
9b431d3
Resave distributed files (GitHub Action)
gadenbuie Sep 11, 2023
5ba05f1
Update website deps (GitHub Action)
gadenbuie Sep 11, 2023
c904328
chore: use {commonmark} instead of includeMarkdown
gadenbuie Sep 11, 2023
42c10c8
Resave distributed files (GitHub Action)
gadenbuie Sep 11, 2023
1204793
feat: Add get started popover help box
gadenbuie Sep 11, 2023
8c0fb87
chore: tweak wording
gadenbuie Sep 11, 2023
55a06cf
chore: Add default to theme styles, remove default button
gadenbuie Sep 11, 2023
485f593
Resave distributed files (GitHub Action)
gadenbuie Sep 11, 2023
a4d88d9
feat: Add loading value box placeholders
gadenbuie Sep 11, 2023
87f00a1
Resave distributed files (GitHub Action)
gadenbuie Sep 11, 2023
81379a7
feat: improve placeholder location/appearance
gadenbuie Sep 12, 2023
e448474
Resave distributed files (GitHub Action)
gadenbuie Sep 12, 2023
4198fba
feat: another approach to the loading state
gadenbuie Sep 12, 2023
b122b8a
Resave distributed files (GitHub Action)
gadenbuie Sep 12, 2023
c196319
Add note about expandable sparklines
gadenbuie Sep 12, 2023
474bccb
ci: don't prefix scss files in inst/examples
gadenbuie Sep 12, 2023
139e63c
docs(value_box): Add note linking to build-a-box app
gadenbuie Sep 12, 2023
a0f0035
docs(pkgdown): Add link ot build a box app in article
gadenbuie Sep 12, 2023
19b3a59
Merged origin/main into feat/box-builder
gadenbuie Sep 12, 2023
e84e12e
Revert "TEMP: deploy shiny apps (REVERT BEFORE MERGING)"
gadenbuie Sep 12, 2023
9a64df9
feat: make "navbar" like icon action area
gadenbuie Sep 13, 2023
1984536
feat: update plot colors when dark mode changes
gadenbuie Sep 13, 2023
809688d
chore: add rstudio/shiny to deploy dependencies
gadenbuie Sep 13, 2023
f6288b3
docs: add news item
gadenbuie Sep 13, 2023
5dbd884
Merge branch 'main' into feat/box-builder
gadenbuie Sep 14, 2023
62dc060
Resave data (GitHub Action)
gadenbuie Sep 14, 2023
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
22 changes: 13 additions & 9 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ jobs:
- name: Install bslib from GitHub
shell: Rscript {0}
run: |
# rsconnect 1.0 introduced an issue with deploying from CI
# Once a proper fix is CRAN, we can go back install.packages
if (!require('remotes')) install.packages('remotes')
remotes::install_version("rsconnect", "0.8.29")
pak::pkg_install("rstudio/bslib", dependencies = TRUE, upgrade = TRUE)

# Workaround for this (probably spurious error):
Expand All @@ -58,18 +54,26 @@ jobs:
run: |
install.packages("cpp11")

- name: Register account
- name: Register account(s)
shell: Rscript {0}
run: |
rsconnect::setAccountInfo(
name = '${{ secrets.SHINYAPPS_NAME }}',
token = '${{ secrets.SHINYAPPS_TOKEN }}',
secret = '${{ secrets.SHINYAPPS_SECRET }}'
)
rsconnect::setAccountInfo(
name = 'bslib',
token = '${{ secrets.SHINYAPPS_BSLIB_TOKEN }}',
secret = '${{ secrets.SHINYAPPS_BSLIB_SECRET }}'
)

- name: Deploy
shell: bash
run: |
Rscript 'inst/themer-demo/deploy.R'
Rscript 'inst/examples/card/deploy.R'
Rscript 'inst/examples/value_box/deploy.R'
Rscript 'inst/examples/flights/deploy.R'
deployScripts=$(find inst -name "deploy.R" -type f)

for deployScript in $deployScripts; do
echo "Deploying $deployScript"
Rscript $deployScript
done
11 changes: 8 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ Suggests:
testthat,
thematic,
withr
Config/Needs/deploy:
Config/Needs/deploy:
BH,
colourpicker,
commonmark,
cpp11,
dplyr,
DT,
Expand All @@ -63,6 +65,7 @@ Config/Needs/deploy:
gt,
hexbin,
histoslider,
htmlwidgets,
lattice,
leaflet,
lubridate,
Expand All @@ -73,9 +76,11 @@ Config/Needs/deploy:
reshape2,
rprojroot,
rsconnect,
scales
scales,
styler,
tibble
Config/Needs/routine: chromote, desc, renv
Config/Needs/website:
Config/Needs/website:
brio,
crosstalk,
dplyr,
Expand Down
11 changes: 11 additions & 0 deletions R/value-box.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
#' `value` represents (for example, it could hold a [bsicons::bs_icon()], or
#' even a [shiny::plotOutput()]).
#'
#' @section Build a Box App:
#'
#' Explore all of the `value_box()` options and layouts interactively with the
#' [Build a Box app](https://bslib.shinyapps.io/build-a-box/), available
#' online thanks to [shinyapps.io](https://www.shinyapps.io/). Or, you can
#' run the app locally with:
#'
#' ```r
#' shiny::runApp(system.file("examples", "build-a-box", package = "bslib"))
#' ```
#'
#' @section Themes:
#'
#' ```{r child="man/fragments/value-box-themes.Rmd"}
Expand Down
34 changes: 34 additions & 0 deletions inst/examples/build-a-box/R/code_modal.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
code_modal <- function(code) {
if (rlang::is_call(code)) {
code <- rlang::expr_text(code)
}

if (requireNamespace("styler", quietly = TRUE)) {
code <- styler::style_text(code)
}

code <- paste(code, collapse = "\n")

showModal(
modalDialog(
HTML(sprintf(
'<pre><code id="value-box-code">%s</code></pre>',
code
)),
p(
id = "copy-clipboard-not-supported",
class = "text-muted d-none",
HTML("Press <kbd>Ctrl</kbd>/<kbd>Cmd</kbd> + <kbd>C</kbd> to copy the value box example code.")
),
tags$button(
id = "copy-code-to-clipboard",
class = "btn btn-outline-primary",
onclick = "copyValueBoxCode()",
"Copy to clipboard"
),
singleton(tags$script(src = "code-modal.js")),
footer = modalButton("Done"),
easyClose = TRUE
)
)
}
37 changes: 37 additions & 0 deletions inst/examples/build-a-box/R/colors.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
theme_colors <- list(
"primary",
"secondary",
"success",
"danger",
"warning",
"info",
"light",
"dark"
)

named_colors <- c(
"blue",
"indigo",
"purple",
"pink",
"red",
"orange",
"yellow",
"green",
"teal",
"cyan"
)

gc <- expand.grid(named_colors, named_colors)
gc <- gc[gc$Var1 != gc$Var2,]
gradient_classes <- sprintf("bg-gradient-%s-%s", gc$Var1, gc$Var2)


all_themes <- c(
"Default" = "",
theme_colors,
named_colors,
paste0("text-", theme_colors),
paste0("text-", named_colors),
sort(gradient_classes)
)
123 changes: 123 additions & 0 deletions inst/examples/build-a-box/R/mod-global-controls.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
ui_global_controls <- function(id) {
ns <- shiny::NS(id)

tagList(
layout_columns(
class = "align-items-end",
selectizeInput(
ns("theme_style"),
"Theme style",
list(
"Default" = "default",
"All" = "all",
"Semantic Colors" = list(
"Semantic Background" = "semantic-bg",
"Semantic Text" = "semantic-fg"
),
"Theme Colors" = list(
"Colored Background" = "colors-bg",
"Colored Text" = "colors-fg"
),
"Vibrant" = list(
"Gradient Background" = "gradient"
)
)
),
shuffleButton(ns("random_theme"), "Theme"),
shuffleButton(ns("random_stat"), "Stats")
),
layout_columns(
class = "align-items-start",
div(
radioButtons(
ns("showcase_item"),
"Showcase Item",
choices = c("Plot", "Icon"),
inline = TRUE
),
conditionalPanel(
"input.showcase_item == 'Plot'",
ns = ns,
p(
class = "text-muted",
"See",
tags$a(href = "https://rstudio.github.io/bslib/articles/value-boxes/index.html#expandable-sparklines", "Expandable Sparklines"),
"for example plot code."
)
),
conditionalPanel(
"input.showcase_item == 'Icon'",
ns = ns,
shuffleButton(ns("random_icon"), "Icons")
)
),
radioButtons(
ns("showcase_layout"),
"Showcase Layout",
choices = c("Left center", "Top right", "Bottom"),
inline = TRUE
)
)
)
cpsievert marked this conversation as resolved.
Show resolved Hide resolved
}

server_global_controls <- function(input, output, sessions, one, two, three) {
observeEvent(c(input$random_theme, input$theme_style), {
new_values <- switch(
input$theme_style,
all = {
one$theme$shuffle()
two$theme$shuffle()
three$theme$shuffle()
NULL
},
default = {
one$theme$set("Default")
two$theme$set("Default")
three$theme$set("Default")
NULL
},
"semantic-bg" = sample(setdiff(theme_colors, c("light", "dark")), 3),
"semantic-fg" = paste0("text-", sample(setdiff(theme_colors, c("light", "dark")), 3)),
"colors-bg" = sample(named_colors, 3, replace = TRUE),
"colors-fg" = paste0("text-", sample(named_colors, 3, replace = TRUE)),
gradient = sample(gradient_classes, 3)
)

if (is.null(new_values)) return()

one$theme$set(new_values[[1]])
two$theme$set(new_values[[2]])
three$theme$set(new_values[[3]])
}, ignoreInit = TRUE)

observeEvent(input$random_stat, {
one$random_stat()
two$random_stat()
three$random_stat()
})

observeEvent(input$random_icon, {
one$showcase_icon$shuffle()
two$showcase_icon$shuffle()
three$showcase_icon$shuffle()
})

observeEvent(input$showcase_item, {
item <- tolower(input$showcase_item)
one$set_showcase_item(item)
two$set_showcase_item(item)
three$set_showcase_item(item)
}, ignoreInit = TRUE)

observeEvent(input$showcase_layout, {
layout <- tolower(input$showcase_layout)
one$set_showcase_layout(layout)
two$set_showcase_layout(layout)
three$set_showcase_layout(layout)
}, ignoreInit = TRUE)
}

module_global_controls <- function(id, one, two, three) {
callModule(server_global_controls, id, one = one, two = two, three = three)
}
Loading
Loading