|
| 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(href = "https://rstudio.github.io/bslib/articles/value-boxes/index.html#expandable-sparklines", "Expandable Sparklines"), |
| 45 | + "for example plot code." |
| 46 | + ) |
| 47 | + ), |
| 48 | + conditionalPanel( |
| 49 | + "input.showcase_item == 'Icon'", |
| 50 | + ns = ns, |
| 51 | + shuffleButton(ns("random_icon"), "Icons") |
| 52 | + ) |
| 53 | + ), |
| 54 | + radioButtons( |
| 55 | + ns("showcase_layout"), |
| 56 | + "Showcase Layout", |
| 57 | + choices = c("Left center", "Top right", "Bottom"), |
| 58 | + inline = TRUE |
| 59 | + ) |
| 60 | + ) |
| 61 | + ) |
| 62 | +} |
| 63 | + |
| 64 | +server_global_controls <- function(input, output, sessions, one, two, three) { |
| 65 | + observeEvent(c(input$random_theme, input$theme_style), { |
| 66 | + new_values <- switch( |
| 67 | + input$theme_style, |
| 68 | + all = { |
| 69 | + one$theme$shuffle() |
| 70 | + two$theme$shuffle() |
| 71 | + three$theme$shuffle() |
| 72 | + NULL |
| 73 | + }, |
| 74 | + default = { |
| 75 | + one$theme$set("Default") |
| 76 | + two$theme$set("Default") |
| 77 | + three$theme$set("Default") |
| 78 | + NULL |
| 79 | + }, |
| 80 | + "semantic-bg" = sample(setdiff(theme_colors, c("light", "dark")), 3), |
| 81 | + "semantic-fg" = paste0("text-", sample(setdiff(theme_colors, c("light", "dark")), 3)), |
| 82 | + "colors-bg" = sample(named_colors, 3, replace = TRUE), |
| 83 | + "colors-fg" = paste0("text-", sample(named_colors, 3, replace = TRUE)), |
| 84 | + gradient = sample(gradient_classes, 3) |
| 85 | + ) |
| 86 | + |
| 87 | + if (is.null(new_values)) return() |
| 88 | + |
| 89 | + one$theme$set(new_values[[1]]) |
| 90 | + two$theme$set(new_values[[2]]) |
| 91 | + three$theme$set(new_values[[3]]) |
| 92 | + }, ignoreInit = TRUE) |
| 93 | + |
| 94 | + observeEvent(input$random_stat, { |
| 95 | + one$random_stat() |
| 96 | + two$random_stat() |
| 97 | + three$random_stat() |
| 98 | + }) |
| 99 | + |
| 100 | + observeEvent(input$random_icon, { |
| 101 | + one$showcase_icon$shuffle() |
| 102 | + two$showcase_icon$shuffle() |
| 103 | + three$showcase_icon$shuffle() |
| 104 | + }) |
| 105 | + |
| 106 | + observeEvent(input$showcase_item, { |
| 107 | + item <- tolower(input$showcase_item) |
| 108 | + one$set_showcase_item(item) |
| 109 | + two$set_showcase_item(item) |
| 110 | + three$set_showcase_item(item) |
| 111 | + }, ignoreInit = TRUE) |
| 112 | + |
| 113 | + observeEvent(input$showcase_layout, { |
| 114 | + layout <- tolower(input$showcase_layout) |
| 115 | + one$set_showcase_layout(layout) |
| 116 | + two$set_showcase_layout(layout) |
| 117 | + three$set_showcase_layout(layout) |
| 118 | + }, ignoreInit = TRUE) |
| 119 | +} |
| 120 | + |
| 121 | +module_global_controls <- function(id, one, two, three) { |
| 122 | + callModule(server_global_controls, id, one = one, two = two, three = three) |
| 123 | +} |
0 commit comments