|
16 | 16 | #' @rdname reactlog_module |
17 | 17 | #' @export |
18 | 18 | #' @examples |
19 | | -#' if (!require("shiny")) { |
20 | | -#' message("`shiny` required to run example") |
21 | | -#' return() |
22 | | -#' } |
23 | | -#' |
24 | | -#' library(shiny) |
25 | | -#' # Enable reactlog |
26 | | -#' reactlog_enable() |
| 19 | +#' if (requireNamespace("shiny", quietly = TRUE)) { |
| 20 | +#' library(shiny) |
| 21 | +#' # Enable reactlog |
| 22 | +#' reactlog_enable() |
27 | 23 | #' |
28 | | -#' # Define UI for app that draws a histogram ---- |
29 | | -#' ui <- fluidPage( |
30 | | -#' tags$h1("Pythagorean theorem"), |
31 | | -#' numericInput("a", "A", 3), |
32 | | -#' numericInput("b", "B", 4), |
33 | | -#' "C:", verbatimTextOutput("c"), |
| 24 | +#' # Define UI for app that draws a histogram ---- |
| 25 | +#' ui <- fluidPage( |
| 26 | +#' tags$h1("Pythagorean theorem"), |
| 27 | +#' numericInput("a", "A", 3), |
| 28 | +#' numericInput("b", "B", 4), |
| 29 | +#' "C:", verbatimTextOutput("c"), |
34 | 30 | #' ### start ui module |
35 | | -#' reactlog_module_ui() |
| 31 | +#' reactlog_module_ui() |
36 | 32 | #' ### end ui module |
37 | | -#' ) |
| 33 | +#' ) |
38 | 34 | #' |
39 | | -#' server <- function(input, output, session) { |
40 | | -#' a2 <- reactive({a <- input$a; req(a); a * a}, label = "a^2") |
41 | | -#' b2 <- reactive({b <- input$b; req(b); b * b}, label = "b^2") |
42 | | -#' c2 <- reactive({a2() + b2()}, label = "c^2") |
43 | | -#' c_val <- reactive({sqrt(c2())}, label = "c") |
| 35 | +#' server <- function(input, output, session) { |
| 36 | +#' a2 <- reactive({a <- input$a; req(a); a * a}, label = "a^2") |
| 37 | +#' b2 <- reactive({b <- input$b; req(b); b * b}, label = "b^2") |
| 38 | +#' c2 <- reactive({a2() + b2()}, label = "c^2") |
| 39 | +#' c_val <- reactive({sqrt(c2())}, label = "c") |
44 | 40 | #' |
45 | | -#' output$c <- renderText({ |
46 | | -#' c_val() |
47 | | -#' }) |
| 41 | +#' output$c <- renderText({ |
| 42 | +#' c_val() |
| 43 | +#' }) |
48 | 44 | #' |
49 | 45 | #' ### start server module |
50 | | -#' reactlog_module_server() |
| 46 | +#' reactlog_module_server() |
51 | 47 | #' ### end server module |
52 | 48 | #' |
53 | | -#' } |
| 49 | +#' } |
54 | 50 | #' |
55 | | -#' if (interactive()) { |
56 | | -#' shinyApp(ui = ui, server = server) |
| 51 | +#' if (interactive()) { |
| 52 | +#' shinyApp(ui = ui, server = server) |
| 53 | +#' } |
57 | 54 | #' } |
58 | 55 | reactlog_module_ui <- function(include_refresh = TRUE, id = "reactlog_module") { |
59 | 56 | ns <- shiny::NS(id) |
@@ -135,13 +132,13 @@ shiny_version_required <- function() { |
135 | 132 | test_shiny_version <- function() { |
136 | 133 | tryCatch({ |
137 | 134 | utils::packageVersion("shiny") >= shiny_version_required() |
138 | | - }, error = function() { |
| 135 | + }, error = function(e) { |
139 | 136 | # package not found |
140 | 137 | FALSE |
141 | 138 | }) |
142 | 139 | } |
143 | 140 | assert_shiny_version <- function() { |
144 | 141 | if (!test_shiny_version()) { |
145 | | - stop("`shiny` v", shiny_version_required, " or greater must be installed") |
| 142 | + stop("`shiny` v", shiny_version_required(), " or greater must be installed") |
146 | 143 | } |
147 | 144 | } |
0 commit comments