| 1 |
ui_global_controls <- function(id) { |
| 2 |
ns <- shiny::NS(id) |
| 3 |
|
| 4 |
tagList( |
| 5 |
layout_columns( |
| 6 |
class = "align-items-end", |
| 7 |
selectizeInput( |
| 8 |
ns("theme_style"), |
| 9 |
"Theme style", |
| 10 |
list( |
| 11 |
"Default" = "default", |
| 12 |
"All" = "all", |
| 13 |
"Semantic Colors" = list( |
| 14 |
"Semantic Background" = "semantic-bg", |
| 15 |
"Semantic Text" = "semantic-fg" |
| 16 |
), |
| 17 |
"Theme Colors" = list( |
| 18 |
"Colored Background" = "colors-bg", |
| 19 |
"Colored Text" = "colors-fg" |
| 20 |
), |
| 21 |
"Vibrant" = list( |
| 22 |
"Gradient Background" = "gradient" |
| 23 |
) |
| 24 |
) |
| 25 |
), |
| 26 |
shuffleButton(ns("random_theme"), "Theme"), |
| 27 |
shuffleButton(ns("random_stat"), "Stats") |
| 28 |
), |
| 29 |
layout_columns( |
| 30 |
class = "align-items-start", |
| 31 |
div( |
| 32 |
radioButtons( |
| 33 |
ns("showcase_item"), |
| 34 |
"Showcase Item", |
| 35 |
choices = c("Plot", "Icon"), |
| 36 |
inline = TRUE |
| 37 |
), |
| 38 |
conditionalPanel( |
| 39 |
"input.showcase_item == 'Plot'", |
| 40 |
ns = ns, |
| 41 |
p( |
| 42 |
class = "text-muted", |
| 43 |
"See", |
| 44 |
tags$a( |
| 45 |
href = "https://rstudio.github.io/bslib/articles/value-boxes/index.html#expandable-sparklines", |
| 46 |
"Expandable Sparklines" |
| 47 |
), |
| 48 |
"for example plot code." |
| 49 |
) |
| 50 |
), |
| 51 |
conditionalPanel( |
| 52 |
"input.showcase_item == 'Icon'", |
| 53 |
ns = ns, |
| 54 |
shuffleButton(ns("random_icon"), "Icons") |
| 55 |
) |
| 56 |
), |
| 57 |
radioButtons( |
| 58 |
ns("showcase_layout"), |
| 59 |
"Showcase Layout", |
| 60 |
choices = c("Left center", "Top right", "Bottom"), |
| 61 |
inline = TRUE |
| 62 |
) |
| 63 |
) |
| 64 |
) |
| 65 |
} |
| 66 |
|
| 67 |
server_global_controls <- function(input, output, sessions, one, two, three) { |
| 68 |
observeEvent( |
| 69 |
c(input$random_theme, input$theme_style), |
| 70 |
{ |
| 71 |
new_values <- switch( |
| 72 |
input$theme_style, |
| 73 |
all = { |
| 74 |
one$theme$shuffle() |
| 75 |
two$theme$shuffle() |
| 76 |
three$theme$shuffle() |
| 77 |
NULL |
| 78 |
}, |
| 79 |
default = { |
| 80 |
one$theme$set("Default") |
| 81 |
two$theme$set("Default") |
| 82 |
three$theme$set("Default") |
| 83 |
NULL |
| 84 |
}, |
| 85 |
"semantic-bg" = sample(setdiff(theme_colors, c("light", "dark")), 3), |
| 86 |
"semantic-fg" = paste0( |
| 87 |
"text-", |
| 88 |
sample(setdiff(theme_colors, c("light", "dark")), 3) |
| 89 |
), |
| 90 |
"colors-bg" = sample(named_colors, 3, replace = TRUE), |
| 91 |
"colors-fg" = paste0("text-", sample(named_colors, 3, replace = TRUE)), |
| 92 |
gradient = sample(gradient_classes, 3) |
| 93 |
) |
| 94 |
|
| 95 |
if (is.null(new_values)) { |
| 96 |
return() |
| 97 |
} |
| 98 |
|
| 99 |
one$theme$set(new_values[[1]]) |
| 100 |
two$theme$set(new_values[[2]]) |
| 101 |
three$theme$set(new_values[[3]]) |
| 102 |
}, |
| 103 |
ignoreInit = TRUE |
| 104 |
) |
| 105 |
|
| 106 |
observeEvent(input$random_stat, { |
| 107 |
one$random_stat() |
| 108 |
two$random_stat() |
| 109 |
three$random_stat() |
| 110 |
}) |
| 111 |
|
| 112 |
observeEvent(input$random_icon, { |
| 113 |
one$showcase_icon$shuffle() |
| 114 |
two$showcase_icon$shuffle() |
| 115 |
three$showcase_icon$shuffle() |
| 116 |
}) |
| 117 |
|
| 118 |
observeEvent( |
| 119 |
input$showcase_item, |
| 120 |
{ |
| 121 |
item <- tolower(input$showcase_item) |
| 122 |
one$set_showcase_item(item) |
| 123 |
two$set_showcase_item(item) |
| 124 |
three$set_showcase_item(item) |
| 125 |
}, |
| 126 |
ignoreInit = TRUE |
| 127 |
) |
| 128 |
|
| 129 |
observeEvent( |
| 130 |
input$showcase_layout, |
| 131 |
{ |
| 132 |
layout <- tolower(input$showcase_layout) |
| 133 |
one$set_showcase_layout(layout) |
| 134 |
two$set_showcase_layout(layout) |
| 135 |
three$set_showcase_layout(layout) |
| 136 |
}, |
| 137 |
ignoreInit = TRUE |
| 138 |
) |
| 139 |
} |
| 140 |
|
| 141 |
module_global_controls <- function(id, one, two, three) { |
| 142 |
callModule(server_global_controls, id, one = one, two = two, three = three) |
| 143 |
} |