diff --git a/main/coverage-report/index.html b/main/coverage-report/index.html index e904ec94c..5aa93a0df 100644 --- a/main/coverage-report/index.html +++ b/main/coverage-report/index.html @@ -107,8 +107,8 @@

teal.modules.general coverage - 3.44%

-
- +
+
@@ -322,8957 +322,8992 @@

teal.modules.general coverage - 3.44%

30 -
#' @examples
+
#' @examplesShinylive
31 -
#' library(teal.widgets)
+
#' library(teal.modules.general)
32 -
#'
+
#' interactive <- function() TRUE
33 -
#' # general data example
+
#' {{ next_example }}
34 -
#' data <- teal_data()
+
# nolint start: line_length_linter.
35 -
#' data <- within(data, {
+
#' @examplesIf require("ggpmisc", quietly = TRUE) && require("ggpp", quietly = TRUE) && require("goftest", quietly = TRUE) && require("MASS", quietly = TRUE) && require("broom", quietly = TRUE)
36 -
#'   iris <- iris
+
# nolint end: line_length_linter.
37 -
#' })
+
#' # general data example
38 -
#' datanames(data) <- "iris"
+
#' data <- teal_data()
39 -
#'
+
#' data <- within(data, {
40 -
#' app <- init(
+
#'   iris <- iris
41 -
#'   data = data,
+
#' })
42 -
#'   modules = list(
+
#' datanames(data) <- "iris"
43 -
#'     tm_g_distribution(
+
#'
44 -
#'       dist_var = data_extract_spec(
+
#' app <- init(
45 -
#'         dataname = "iris",
+
#'   data = data,
46 -
#'         select = select_spec(variable_choices("iris"), "Petal.Length")
+
#'   modules = list(
47 -
#'       ),
+
#'     tm_g_distribution(
48 -
#'       ggplot2_args = ggplot2_args(
+
#'       dist_var = data_extract_spec(
49 -
#'         labs = list(subtitle = "Plot generated by Distribution Module")
+
#'         dataname = "iris",
50 -
#'       )
+
#'         select = select_spec(variable_choices("iris"), "Petal.Length")
51 -
#'     )
+
#'       )
52 -
#'   )
+
#'     )
53 -
#' )
+
#'   )
54 -
#' if (interactive()) {
+
#' )
55 -
#'   shinyApp(app$ui, app$server)
+
#' if (interactive()) {
56 -
#' }
+
#'   shinyApp(app$ui, app$server)
57 -
#'
+
#' }
58 -
#' # CDISC data example
+
#'
59 -
#' data <- teal_data()
+
#' @examplesShinylive
60 -
#' data <- within(data, {
+
#' library(teal.modules.general)
61 -
#'   ADSL <- rADSL
+
#' interactive <- function() TRUE
62 -
#' })
+
#' {{ next_example }}
63 -
#' datanames(data) <- c("ADSL")
+
# nolint start: line_length_linter.
64 -
#' join_keys(data) <- default_cdisc_join_keys[datanames(data)]
+
#' @examplesIf require("ggpmisc", quietly = TRUE) && require("ggpp", quietly = TRUE) && require("goftest", quietly = TRUE) && require("MASS", quietly = TRUE) && require("broom", quietly = TRUE)
65 -
#'
+
# nolint end: line_length_linter.
66 -
#' vars1 <- choices_selected(
+
#' # CDISC data example
67 -
#'   variable_choices(data[["ADSL"]], c("ARM", "COUNTRY", "SEX")),
+
#' data <- teal_data()
68 -
#'   selected = NULL
+
#' data <- within(data, {
69 -
#' )
+
#'   ADSL <- rADSL
70 -
#'
+
#' })
71 -
#' app <- init(
+
#' datanames(data) <- c("ADSL")
72 -
#'   data = data,
+
#' join_keys(data) <- default_cdisc_join_keys[datanames(data)]
73 -
#'   modules = modules(
+
#'
74 -
#'     tm_g_distribution(
+
#' vars1 <- choices_selected(
75 -
#'       dist_var = data_extract_spec(
+
#'   variable_choices(data[["ADSL"]], c("ARM", "COUNTRY", "SEX")),
76 -
#'         dataname = "ADSL",
+
#'   selected = NULL
77 -
#'         select = select_spec(
+
#' )
78 -
#'           choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")),
+
#'
79 -
#'           selected = "BMRKR1",
+
#' app <- init(
80 -
#'           multiple = FALSE,
+
#'   data = data,
81 -
#'           fixed = FALSE
+
#'   modules = modules(
82 -
#'         )
+
#'     tm_g_distribution(
83 -
#'       ),
+
#'       dist_var = data_extract_spec(
84 -
#'       strata_var = data_extract_spec(
+
#'         dataname = "ADSL",
85 -
#'         dataname = "ADSL",
+
#'         select = select_spec(
86 -
#'         filter = filter_spec(
+
#'           choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")),
87 -
#'           vars = vars1,
+
#'           selected = "BMRKR1",
88 -
#'           multiple = TRUE
+
#'           multiple = FALSE,
89 -
#'         )
+
#'           fixed = FALSE
90 -
#'       ),
+
#'         )
91 -
#'       group_var = data_extract_spec(
+
#'       ),
92 -
#'         dataname = "ADSL",
+
#'       strata_var = data_extract_spec(
93 -
#'         filter = filter_spec(
+
#'         dataname = "ADSL",
94 -
#'           vars = vars1,
+
#'         filter = filter_spec(
95 -
#'           multiple = TRUE
+
#'           vars = vars1,
96 -
#'         )
+
#'           multiple = TRUE
97 -
#'       ),
+
#'         )
98 -
#'       ggplot2_args = ggplot2_args(
+
#'       ),
99 -
#'         labs = list(subtitle = "Plot generated by Distribution Module")
+
#'       group_var = data_extract_spec(
100 -
#'       )
+
#'         dataname = "ADSL",
101 -
#'     )
+
#'         filter = filter_spec(
102 -
#'   )
+
#'           vars = vars1,
103 -
#' )
+
#'           multiple = TRUE
104 -
#' if (interactive()) {
+
#'         )
105 -
#'   shinyApp(app$ui, app$server)
+
#'       )
106 -
#' }
+
#'     )
107 -
#'
+
#'   )
108 -
#' @export
+
#' )
109 -
#'
+
#' if (interactive()) {
110 -
tm_g_distribution <- function(label = "Distribution Module",
+
#'   shinyApp(app$ui, app$server)
111 -
                              dist_var,
+
#' }
112 -
                              strata_var = NULL,
+
#'
113 -
                              group_var = NULL,
+
#' @export
114 -
                              freq = FALSE,
+
#'
115 -
                              ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
+
tm_g_distribution <- function(label = "Distribution Module",
116 -
                              ggplot2_args = teal.widgets::ggplot2_args(),
+
                              dist_var,
117 -
                              bins = c(30L, 1L, 100L),
+
                              strata_var = NULL,
118 -
                              plot_height = c(600, 200, 2000),
+
                              group_var = NULL,
119 -
                              plot_width = NULL,
+
                              freq = FALSE,
120 -
                              pre_output = NULL,
+
                              ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
121 + +
                              ggplot2_args = teal.widgets::ggplot2_args(),
+ + + + 122 + + +
                              bins = c(30L, 1L, 100L),
+ + + + 123 + + +
                              plot_height = c(600, 200, 2000),
+ + + + 124 + + +
                              plot_width = NULL,
+ + + + 125 + + +
                              pre_output = NULL,
+ + + + 126 +
                              post_output = NULL) {
- 122 + 127 !
  message("Initializing tm_g_distribution")
- 123 + 128

                     
                   
                   
-                    124
+                    129
                     
                     
                       
  # Requires Suggested packages
- 125 + 130 !
  extra_packages <- c("ggpmisc", "ggpp", "goftest", "MASS", "broom")
- 126 + 131 !
  missing_packages <- Filter(function(x) !requireNamespace(x, quietly = TRUE), extra_packages)
- 127 + 132 !
  if (length(missing_packages) > 0L) {
- 128 + 133 !
    stop(sprintf(
- 129 + 134 !
      "Cannot load package(s): %s.\nInstall or restart your session.",
- 130 + 135 !
      toString(missing_packages)
- 131 + 136
    ))
- 132 + 137
  }
- 133 + 138

                     
                   
                   
-                    134
+                    139
                     
                     
                       
  # Normalize the parameters
- 135 + 140 !
  if (inherits(dist_var, "data_extract_spec")) dist_var <- list(dist_var)
- 136 + 141 !
  if (inherits(strata_var, "data_extract_spec")) strata_var <- list(strata_var)
- 137 + 142 !
  if (inherits(group_var, "data_extract_spec")) group_var <- list(group_var)
- 138 + 143 !
  if (inherits(ggplot2_args, "ggplot2_args")) ggplot2_args <- list(default = ggplot2_args)
- 139 + 144

                     
                   
                   
-                    140
+                    145
                     
                     
                       
  # Start of assertions
- 141 + 146 !
  checkmate::assert_string(label)
- 142 + 147

                     
                   
                   
-                    143
+                    148
                     !
                     
                       
  checkmate::assert_list(dist_var, "data_extract_spec")
- 144 + 149 !
  checkmate::assert_false(dist_var[[1L]]$select$multiple)
- 145 + 150

                     
                   
                   
-                    146
+                    151
                     !
                     
                       
  checkmate::assert_list(strata_var, types = "data_extract_spec", null.ok = TRUE)
- 147 + 152 !
  checkmate::assert_list(group_var, types = "data_extract_spec", null.ok = TRUE)
- 148 + 153 !
  checkmate::assert_flag(freq)
- 149 + 154 !
  ggtheme <- match.arg(ggtheme)
- 150 + 155

                     
                   
                   
-                    151
+                    156
                     !
                     
                       
  plot_choices <- c("Histogram", "QQplot")
- 152 + 157 !
  checkmate::assert_list(ggplot2_args, types = "ggplot2_args")
- 153 + 158 !
  checkmate::assert_subset(names(ggplot2_args), c("default", plot_choices))
- 154 + 159

                     
                   
                   
-                    155
+                    160
                     !
                     
                       
  if (length(bins) == 1) {
- 156 + 161 !
    checkmate::assert_numeric(bins, any.missing = FALSE, lower = 1)
- 157 + 162
  } else {
- 158 + 163 !
    checkmate::assert_numeric(bins, len = 3, any.missing = FALSE, lower = 1)
- 159 + 164 !
    checkmate::assert_numeric(bins[1], lower = bins[2], upper = bins[3], .var.name = "bins")
- 160 + 165
  }
- 161 + 166

                     
                   
                   
-                    162
+                    167
                     !
                     
                       
  checkmate::assert_numeric(plot_height, len = 3, any.missing = FALSE, finite = TRUE)
- 163 + 168 !
  checkmate::assert_numeric(plot_height[1], lower = plot_height[2], upper = plot_height[3], .var.name = "plot_height")
- 164 + 169 !
  checkmate::assert_numeric(plot_width, len = 3, any.missing = FALSE, null.ok = TRUE, finite = TRUE)
- 165 + 170 !
  checkmate::assert_numeric(
- 166 + 171 !
    plot_width[1],
- 167 + 172 !
    lower = plot_width[2], upper = plot_width[3], null.ok = TRUE, .var.name = "plot_width"
- 168 + 173
  )
- 169 + 174

                     
                   
                   
-                    170
+                    175
                     !
                     
                       
  checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
- 171 + 176 !
  checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
- 172 + 177
  # End of assertions
- 173 + 178

                     
                   
                   
-                    174
+                    179
                     
                     
                       
  # Make UI args
- 175 + 180 !
  args <- as.list(environment())
- 176 + 181

                     
                   
                   
-                    177
+                    182
                     !
                     
                       
  data_extract_list <- list(
- 178 + 183 !
    dist_var = dist_var,
- 179 + 184 !
    strata_var = strata_var,
- 180 + 185 !
    group_var = group_var
- 181 + 186
  )
- 182 + 187

                     
                   
                   
-                    183
+                    188
                     !
                     
                       
  ans <- module(
- 184 + 189 !
    label = label,
- 185 + 190 !
    server = srv_distribution,
- 186 + 191 !
    server_args = c(
- 187 + 192 !
      data_extract_list,
- 188 + 193 !
      list(plot_height = plot_height, plot_width = plot_width, ggplot2_args = ggplot2_args)
- 189 + 194
    ),
- 190 + 195 !
    ui = ui_distribution,
- 191 + 196 !
    ui_args = args,
- 192 + 197 !
    datanames = teal.transform::get_extract_datanames(data_extract_list)
- 193 + 198
  )
- 194 + 199 !
  attr(ans, "teal_bookmarkable") <- TRUE
- 195 + 200 !
  ans
- 196 + 201
}
- 197 + 202

                     
                   
                   
-                    198
+                    203
                     
                     
                       
# UI function for the distribution module
- 199 + 204
ui_distribution <- function(id, ...) {
- 200 + 205 !
  args <- list(...)
- 201 + 206 !
  ns <- NS(id)
- 202 + 207 !
  is_single_dataset_value <- teal.transform::is_single_dataset(args$dist_var, args$strata_var, args$group_var)
- 203 + 208

                     
                   
                   
-                    204
+                    209
                     !
                     
                       
  teal.widgets::standard_layout(
- 205 + 210 !
    output = teal.widgets::white_small_well(
- 206 + 211 !
      tabsetPanel(
- 207 + 212 !
        id = ns("tabs"),
- 208 + 213 !
        tabPanel("Histogram", teal.widgets::plot_with_settings_ui(id = ns("hist_plot"))),
- 209 + 214 !
        tabPanel("QQplot", teal.widgets::plot_with_settings_ui(id = ns("qq_plot")))
- 210 + 215
      ),
- 211 + 216 !
      tags$h3("Statistics Table"),
- 212 + 217 !
      DT::dataTableOutput(ns("summary_table")),
- 213 + 218 !
      tags$h3("Tests"),
- 214 + 219 !
      DT::dataTableOutput(ns("t_stats"))
- 215 + 220
    ),
- 216 + 221 !
    encoding = tags$div(
- 217 + 222
      ### Reporter
- 218 + 223 !
      teal.reporter::simple_reporter_ui(ns("simple_reporter")),
- 219 + 224
      ###
- 220 + 225 !
      tags$label("Encodings", class = "text-primary"),
- 221 + 226 !
      teal.transform::datanames_input(args[c("dist_var", "strata_var")]),
- 222 + 227 !
      teal.transform::data_extract_ui(
- 223 + 228 !
        id = ns("dist_i"),
- 224 + 229 !
        label = "Variable",
- 225 + 230 !
        data_extract_spec = args$dist_var,
- 226 + 231 !
        is_single_dataset = is_single_dataset_value
- 227 + 232
      ),
- 228 + 233 !
      if (!is.null(args$group_var)) {
- 229 + 234 !
        tagList(
- 230 + 235 !
          teal.transform::data_extract_ui(
- 231 + 236 !
            id = ns("group_i"),
- 232 + 237 !
            label = "Group by",
- 233 + 238 !
            data_extract_spec = args$group_var,
- 234 + 239 !
            is_single_dataset = is_single_dataset_value
- 235 + 240
          ),
- 236 + 241 !
          uiOutput(ns("scales_types_ui"))
- 237 + 242
        )
- 238 + 243
      },
- 239 + 244 !
      if (!is.null(args$strata_var)) {
- 240 + 245 !
        teal.transform::data_extract_ui(
- 241 + 246 !
          id = ns("strata_i"),
- 242 + 247 !
          label = "Stratify by",
- 243 + 248 !
          data_extract_spec = args$strata_var,
- 244 + 249 !
          is_single_dataset = is_single_dataset_value
- 245 + 250
        )
- 246 + 251
      },
- 247 + 252 !
      teal.widgets::panel_group(
- 248 + 253 !
        conditionalPanel(
- 249 + 254 !
          condition = paste0("input['", ns("tabs"), "'] == 'Histogram'"),
- 250 + 255 !
          teal.widgets::panel_item(
- 251 + 256 !
            "Histogram",
- 252 + 257 !
            teal.widgets::optionalSliderInputValMinMax(ns("bins"), "Bins", args$bins, ticks = FALSE, step = 1),
- 253 + 258 !
            shinyWidgets::prettyRadioButtons(
- 254 + 259 !
              ns("main_type"),
- 255 + 260 !
              label = "Plot Type:",
- 256 + 261 !
              choices = c("Density", "Frequency"),
- 257 + 262 !
              selected = if (!args$freq) "Density" else "Frequency",
- 258 + 263 !
              bigger = FALSE,
- 259 + 264 !
              inline = TRUE
- 260 + 265
            ),
- 261 + 266 !
            checkboxInput(ns("add_dens"), label = "Overlay Density", value = TRUE),
- 262 + 267 !
            collapsed = FALSE
- 263 + 268
          )
- 264 + 269
        ),
- 265 + 270 !
        conditionalPanel(
- 266 + 271 !
          condition = paste0("input['", ns("tabs"), "'] == 'QQplot'"),
- 267 + 272 !
          teal.widgets::panel_item(
- 268 + 273 !
            "QQ Plot",
- 269 + 274 !
            checkboxInput(ns("qq_line"), label = "Add diagonal line(s)", TRUE),
- 270 + 275 !
            collapsed = FALSE
- 271 + 276
          )
- 272 + 277
        ),
- 273 + 278 !
        conditionalPanel(
- 274 + 279 !
          condition = paste0("input['", ns("main_type"), "'] == 'Density'"),
- 275 + 280 !
          teal.widgets::panel_item(
- 276 + 281 !
            "Theoretical Distribution",
- 277 + 282 !
            teal.widgets::optionalSelectInput(
- 278 + 283 !
              ns("t_dist"),
- 279 + 284 !
              tags$div(
- 280 + 285 !
                class = "teal-tooltip",
- 281 + 286 !
                tagList(
- 282 + 287 !
                  "Distribution:",
- 283 + 288 !
                  icon("circle-info"),
- 284 + 289 !
                  tags$span(
- 285 + 290 !
                    class = "tooltiptext",
- 286 + 291 !
                    "Default parameters are optimized with MASS::fitdistr function."
- 287 + 292
                  )
- 288 + 293
                )
- 289 + 294
              ),
- 290 + 295 !
              choices = c("normal", "lognormal", "gamma", "unif"),
- 291 + 296 !
              selected = NULL,
- 292 + 297 !
              multiple = FALSE
- 293 + 298
            ),
- 294 + 299 !
            numericInput(ns("dist_param1"), label = "param1", value = NULL),
- 295 + 300 !
            numericInput(ns("dist_param2"), label = "param2", value = NULL),
- 296 + 301 !
            tags$span(actionButton(ns("params_reset"), "Default params")),
- 297 + 302 !
            collapsed = FALSE
- 298 + 303
          )
- 299 + 304
        )
- 300 + 305
      ),
- 301 + 306 !
      teal.widgets::panel_item(
- 302 + 307 !
        "Tests",
- 303 + 308 !
        teal.widgets::optionalSelectInput(
- 304 + 309 !
          ns("dist_tests"),
- 305 + 310 !
          "Tests:",
- 306 + 311 !
          choices = c(
- 307 + 312 !
            "Shapiro-Wilk",
- 308 + 313 !
            if (!is.null(args$strata_var)) "t-test (two-samples, not paired)",
- 309 + 314 !
            if (!is.null(args$strata_var)) "one-way ANOVA",
- 310 + 315 !
            if (!is.null(args$strata_var)) "Fligner-Killeen",
- 311 + 316 !
            if (!is.null(args$strata_var)) "F-test",
- 312 + 317 !
            "Kolmogorov-Smirnov (one-sample)",
- 313 + 318 !
            "Anderson-Darling (one-sample)",
- 314 + 319 !
            "Cramer-von Mises (one-sample)",
- 315 + 320 !
            if (!is.null(args$strata_var)) "Kolmogorov-Smirnov (two-samples)"
- 316 + 321
          ),
- 317 + 322 !
          selected = NULL
- 318 + 323
        )
- 319 + 324
      ),
- 320 + 325 !
      teal.widgets::panel_item(
- 321 + 326 !
        "Statistics Table",
- 322 + 327 !
        sliderInput(ns("roundn"), "Round to n digits", min = 0, max = 10, value = 2)
- 323 + 328
      ),
- 324 + 329 !
      teal.widgets::panel_item(
- 325 + 330 !
        title = "Plot settings",
- 326 + 331 !
        selectInput(
- 327 + 332 !
          inputId = ns("ggtheme"),
- 328 + 333 !
          label = "Theme (by ggplot):",
- 329 + 334 !
          choices = ggplot_themes,
- 330 + 335 !
          selected = args$ggtheme,
- 331 + 336 !
          multiple = FALSE
- 332 + 337
        )
- 333 + 338
      )
- 334 + 339
    ),
- 335 + 340 !
    forms = tagList(
- 336 + 341 !
      teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
- 337 + 342
    ),
- 338 + 343 !
    pre_output = args$pre_output,
- 339 + 344 !
    post_output = args$post_output
- 340 + 345
  )
- 341 + 346
}
- 342 + 347

                     
                   
                   
-                    343
+                    348
                     
                     
                       
# Server function for the distribution module
- 344 + 349
srv_distribution <- function(id,
- 345 + 350
                             data,
- 346 + 351
                             reporter,
- 347 + 352
                             filter_panel_api,
- 348 + 353
                             dist_var,
- 349 + 354
                             strata_var,
- 350 + 355
                             group_var,
- 351 + 356
                             plot_height,
- 352 + 357
                             plot_width,
- 353 + 358
                             ggplot2_args) {
- 354 + 359 !
  with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
- 355 + 360 !
  with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
- 356 + 361 !
  checkmate::assert_class(data, "reactive")
- 357 + 362 !
  checkmate::assert_class(isolate(data()), "teal_data")
- 358 + 363 !
  moduleServer(id, function(input, output, session) {
- 359 + 364 !
    teal.logger::log_shiny_input_changes(input, namespace = "teal.modules.general")
- 360 + 365

                     
                   
                   
-                    361
+                    366
                     !
                     
                       
    setBookmarkExclude("params_reset")
- 362 + 367

                     
                   
                   
-                    363
+                    368
                     !
                     
                       
    ns <- session$ns
- 364 + 369

                     
                   
                   
-                    365
+                    370
                     !
                     
                       
    rule_req <- function(value) {
- 366 + 371 !
      if (isTRUE(input$dist_tests %in% c(
- 367 + 372 !
        "Fligner-Killeen",
- 368 + 373 !
        "t-test (two-samples, not paired)",
- 369 + 374 !
        "F-test",
- 370 + 375 !
        "Kolmogorov-Smirnov (two-samples)",
- 371 + 376 !
        "one-way ANOVA"
- 372 + 377
      ))) {
- 373 + 378 !
        if (!shinyvalidate::input_provided(value)) {
- 374 + 379 !
          "Please select stratify variable."
- 375 + 380
        }
- 376 + 381
      }
- 377 + 382
    }
- 378 + 383 !
    rule_dupl <- function(...) {
- 379 + 384 !
      if (identical(input$dist_tests, "Fligner-Killeen")) {
- 380 + 385 !
        strata <- selector_list()$strata_i()$select
- 381 + 386 !
        group <- selector_list()$group_i()$select
- 382 + 387 !
        if (isTRUE(strata == group)) {
- 383 + 388 !
          "Please select different variables for strata and group."
- 384 + 389
        }
- 385 + 390
      }
- 386 + 391
    }
- 387 + 392

                     
                   
                   
-                    388
+                    393
                     !
                     
                       
    selector_list <- teal.transform::data_extract_multiple_srv(
- 389 + 394 !
      data_extract = list(
- 390 + 395 !
        dist_i = dist_var,
- 391 + 396 !
        strata_i = strata_var,
- 392 + 397 !
        group_i = group_var
- 393 + 398
      ),
- 394 + 399 !
      data,
- 395 + 400 !
      select_validation_rule = list(
- 396 + 401 !
        dist_i = shinyvalidate::sv_required("Please select a variable")
- 397 + 402
      ),
- 398 + 403 !
      filter_validation_rule = list(
- 399 + 404 !
        strata_i = shinyvalidate::compose_rules(
- 400 + 405 !
          rule_req,
- 401 + 406 !
          rule_dupl
- 402 + 407
        ),
- 403 + 408 !
        group_i = rule_dupl
- 404 + 409
      )
- 405 + 410
    )
- 406 + 411

                     
                   
                   
-                    407
+                    412
                     !
                     
                       
    iv_r <- reactive({
- 408 + 413 !
      iv <- shinyvalidate::InputValidator$new()
- 409 + 414 !
      teal.transform::compose_and_enable_validators(iv, selector_list, validator_names = "dist_i")
- 410 + 415
    })
- 411 + 416

                     
                   
                   
-                    412
+                    417
                     !
                     
                       
    iv_r_dist <- reactive({
- 413 + 418 !
      iv <- shinyvalidate::InputValidator$new()
- 414 + 419 !
      teal.transform::compose_and_enable_validators(
- 415 + 420 !
        iv, selector_list,
- 416 + 421 !
        validator_names = c("strata_i", "group_i")
- 417 + 422
      )
- 418 + 423
    })
- 419 + 424 !
    rule_dist_1 <- function(value) {
- 420 + 425 !
      if (!is.null(input$t_dist)) {
- 421 + 426 !
        switch(input$t_dist,
- 422 + 427 !
          "normal" = if (!shinyvalidate::input_provided(value)) "mean is required",
- 423 + 428 !
          "lognormal" = if (!shinyvalidate::input_provided(value)) "meanlog is required",
- 424 + 429 !
          "gamma" = {
- 425 + 430 !
            if (!shinyvalidate::input_provided(value)) "shape is required" else if (value <= 0) "shape must be positive"
- 426 + 431
          },
- 427 + 432 !
          "unif" = NULL
- 428 + 433
        )
- 429 + 434
      }
- 430 + 435
    }
- 431 + 436 !
    rule_dist_2 <- function(value) {
- 432 + 437 !
      if (!is.null(input$t_dist)) {
- 433 + 438 !
        switch(input$t_dist,
- 434 + 439 !
          "normal" = {
- 435 + 440 !
            if (!shinyvalidate::input_provided(value)) {
- 436 + 441 !
              "sd is required"
- 437 + 442 !
            } else if (value < 0) {
- 438 + 443 !
              "sd must be non-negative"
- 439 + 444
            }
- 440 + 445
          },
- 441 + 446 !
          "lognormal" = {
- 442 + 447 !
            if (!shinyvalidate::input_provided(value)) {
- 443 + 448 !
              "sdlog is required"
- 444 + 449 !
            } else if (value < 0) {
- 445 + 450 !
              "sdlog must be non-negative"
- 446 + 451
            }
- 447 + 452
          },
- 448 + 453 !
          "gamma" = {
- 449 + 454 !
            if (!shinyvalidate::input_provided(value)) {
- 450 + 455 !
              "rate is required"
- 451 + 456 !
            } else if (value <= 0) {
- 452 + 457 !
              "rate must be positive"
- 453 + 458
            }
- 454 + 459
          },
- 455 + 460 !
          "unif" = NULL
- 456 + 461
        )
- 457 + 462
      }
- 458 + 463
    }
- 459 + 464 !
    rule_dist <- function(value) {
- 460 + 465 !
      if (isTRUE(input$tabs == "QQplot" ||
- 461 + 466 !
        input$dist_tests %in% c(
- 462 + 467 !
          "Kolmogorov-Smirnov (one-sample)",
- 463 + 468 !
          "Anderson-Darling (one-sample)",
- 464 + 469 !
          "Cramer-von Mises (one-sample)"
- 465 + 470
        ))) {
- 466 + 471 !
        if (!shinyvalidate::input_provided(value)) {
- 467 + 472 !
          "Please select the theoretical distribution."
- 468 + 473
        }
- 469 + 474
      }
- 470 + 475
    }
- 471 + 476 !
    iv_dist <- shinyvalidate::InputValidator$new()
- 472 + 477 !
    iv_dist$add_rule("t_dist", rule_dist)
- 473 + 478 !
    iv_dist$add_rule("dist_param1", rule_dist_1)
- 474 + 479 !
    iv_dist$add_rule("dist_param2", rule_dist_2)
- 475 + 480 !
    iv_dist$enable()
- 476 + 481

                     
                   
                   
-                    477
+                    482
                     !
                     
                       
    anl_merged_input <- teal.transform::merge_expression_srv(
- 478 + 483 !
      selector_list = selector_list,
- 479 + 484 !
      datasets = data
- 480 + 485
    )
- 481 + 486

                     
                   
                   
-                    482
+                    487
                     !
                     
                       
    anl_merged_q <- reactive({
- 483 + 488 !
      req(anl_merged_input())
- 484 + 489 !
      data() %>%
- 485 + 490 !
        teal.code::eval_code(as.expression(anl_merged_input()$expr))
- 486 + 491
    })
- 487 + 492

                     
                   
                   
-                    488
+                    493
                     !
                     
                       
    merged <- list(
- 489 + 494 !
      anl_input_r = anl_merged_input,
- 490 + 495 !
      anl_q_r = anl_merged_q
- 491 + 496
    )
- 492 + 497

                     
                   
                   
-                    493
+                    498
                     !
                     
                       
    output$scales_types_ui <- renderUI({
- 494 + 499 !
      if ("group_i" %in% names(selector_list()) && length(selector_list()$group_i()$filters[[1]]$selected) > 0) {
- 495 + 500 !
        shinyWidgets::prettyRadioButtons(
- 496 + 501 !
          ns("scales_type"),
- 497 + 502 !
          label = "Scales:",
- 498 + 503 !
          choices = c("Fixed", "Free"),
- 499 + 504 !
          selected = "Fixed",
- 500 + 505 !
          bigger = FALSE,
- 501 + 506 !
          inline = TRUE
- 502 + 507
        )
- 503 + 508
      }
- 504 + 509
    })
- 505 + 510

                     
                   
                   
-                    506
+                    511
                     !
                     
                       
    observeEvent(
- 507 + 512 !
      eventExpr = list(
- 508 + 513 !
        input$t_dist,
- 509 + 514 !
        input$params_reset,
- 510 + 515 !
        selector_list()$dist_i()$select
- 511 + 516
      ),
- 512 + 517 !
      handlerExpr = {
- 513 + 518 !
        params <-
- 514 + 519 !
          if (length(input$t_dist) != 0) {
- 515 + 520 !
            get_dist_params <- function(x, dist) {
- 516 + 521 !
              if (dist == "unif") {
- 517 + 522 !
                return(stats::setNames(range(x, na.rm = TRUE), c("min", "max")))
- 518 + 523
              }
- 519 + 524 !
              tryCatch(
- 520 + 525 !
                MASS::fitdistr(x, densfun = dist)$estimate,
- 521 + 526 !
                error = function(e) c(param1 = NA_real_, param2 = NA_real_)
- 522 + 527
              )
- 523 + 528
            }
- 524 + 529

                     
                   
                   
-                    525
+                    530
                     !
                     
                       
            ANL <- merged$anl_q_r()[["ANL"]]
- 526 + 531 !
            round(get_dist_params(as.numeric(stats::na.omit(ANL[[merge_vars()$dist_var]])), input$t_dist), 2)
- 527 + 532
          } else {
- 528 + 533 !
            c("param1" = NA_real_, "param2" = NA_real_)
- 529 + 534
          }
- 530 + 535

                     
                   
                   
-                    531
+                    536
                     !
                     
                       
        params_vals <- unname(params)
- 532 + 537 !
        params_names <- names(params)
- 533 + 538

                     
                   
                   
-                    534
+                    539
                     !
                     
                       
        updateNumericInput(
- 535 + 540 !
          inputId = "dist_param1",
- 536 + 541 !
          label = params_names[1],
- 537 + 542 !
          value = restoreInput(ns("dist_param1"), params_vals[1])
- 538 + 543
        )
- 539 + 544 !
        updateNumericInput(
- 540 + 545 !
          inputId = "dist_param2",
- 541 + 546 !
          label = params_names[2],
- 542 + 547 !
          value = restoreInput(ns("dist_param1"), params_vals[2])
- 543 + 548
        )
- 544 + 549
      },
- 545 + 550 !
      ignoreInit = TRUE
- 546 + 551
    )
- 547 + 552

                     
                   
                   
-                    548
+                    553
                     !
                     
                       
    observeEvent(input$params_reset, {
- 549 + 554 !
      updateActionButton(inputId = "params_reset", label = "Reset params")
- 550 + 555
    })
- 551 + 556

                     
                   
                   
-                    552
+                    557
                     !
                     
                       
    merge_vars <- reactive({
- 553 + 558 !
      teal::validate_inputs(iv_r())
- 554 + 559

                     
                   
                   
-                    555
+                    560
                     !
                     
                       
      dist_var <- as.vector(merged$anl_input_r()$columns_source$dist_i)
- 556 + 561 !
      s_var <- as.vector(merged$anl_input_r()$columns_source$strata_i)
- 557 + 562 !
      g_var <- as.vector(merged$anl_input_r()$columns_source$group_i)
- 558 + 563

                     
                   
                   
-                    559
+                    564
                     !
                     
                       
      dist_var_name <- if (length(dist_var)) as.name(dist_var) else NULL
- 560 + 565 !
      s_var_name <- if (length(s_var)) as.name(s_var) else NULL
- 561 + 566 !
      g_var_name <- if (length(g_var)) as.name(g_var) else NULL
- 562 + 567

                     
                   
                   
-                    563
+                    568
                     !
                     
                       
      list(
- 564 + 569 !
        dist_var = dist_var,
- 565 + 570 !
        s_var = s_var,
- 566 + 571 !
        g_var = g_var,
- 567 + 572 !
        dist_var_name = dist_var_name,
- 568 + 573 !
        s_var_name = s_var_name,
- 569 + 574 !
        g_var_name = g_var_name
- 570 + 575
      )
- 571 + 576
    })
- 572 + 577

                     
                   
                   
-                    573
+                    578
                     
                     
                       
    # common qenv
- 574 + 579 !
    common_q <- reactive({
- 575 + 580
      # Create a private stack for this function only.
- 576 + 581

                     
                   
                   
-                    577
+                    582
                     !
                     
                       
      ANL <- merged$anl_q_r()[["ANL"]]
- 578 + 583 !
      dist_var <- merge_vars()$dist_var
- 579 + 584 !
      s_var <- merge_vars()$s_var
- 580 + 585 !
      g_var <- merge_vars()$g_var
- 581 + 586

                     
                   
                   
-                    582
+                    587
                     !
                     
                       
      dist_var_name <- merge_vars()$dist_var_name
- 583 + 588 !
      s_var_name <- merge_vars()$s_var_name
- 584 + 589 !
      g_var_name <- merge_vars()$g_var_name
- 585 + 590

                     
                   
                   
-                    586
+                    591
                     !
                     
                       
      roundn <- input$roundn
- 587 + 592 !
      dist_param1 <- input$dist_param1
- 588 + 593 !
      dist_param2 <- input$dist_param2
- 589 + 594
      # isolated as dist_param1/dist_param2 already triggered the reactivity
- 590 + 595 !
      t_dist <- isolate(input$t_dist)
- 591 + 596

                     
                   
                   
-                    592
+                    597
                     !
                     
                       
      qenv <- merged$anl_q_r()
- 593 + 598

                     
                   
                   
-                    594
+                    599
                     !
                     
                       
      if (length(g_var) > 0) {
- 595 + 600 !
        validate(
- 596 + 601 !
          need(
- 597 + 602 !
            inherits(ANL[[g_var]], c("integer", "factor", "character")),
- 598 + 603 !
            "Group by variable must be `factor`, `character`, or `integer`"
- 599 + 604
          )
- 600 + 605
        )
- 601 + 606 !
        qenv <- teal.code::eval_code(
- 602 + 607 !
          qenv,
- 603 + 608 !
          substitute(
- 604 + 609 !
            expr = ANL[[g_var]] <- forcats::fct_na_value_to_level(as.factor(ANL[[g_var]]), "NA"),
- 605 + 610 !
            env = list(g_var = g_var)
- 606 + 611
          )
- 607 + 612
        )
- 608 + 613
      }
- 609 + 614

                     
                   
                   
-                    610
+                    615
                     !
                     
                       
      if (length(s_var) > 0) {
- 611 + 616 !
        validate(
- 612 + 617 !
          need(
- 613 + 618 !
            inherits(ANL[[s_var]], c("integer", "factor", "character")),
- 614 + 619 !
            "Stratify by variable must be `factor`, `character`, or `integer`"
- 615 + 620
          )
- 616 + 621
        )
- 617 + 622 !
        qenv <- teal.code::eval_code(
- 618 + 623 !
          qenv,
- 619 + 624 !
          substitute(
- 620 + 625 !
            expr = ANL[[s_var]] <- forcats::fct_na_value_to_level(as.factor(ANL[[s_var]]), "NA"),
- 621 + 626 !
            env = list(s_var = s_var)
- 622 + 627
          )
- 623 + 628
        )
- 624 + 629
      }
- 625 + 630

                     
                   
                   
-                    626
+                    631
                     !
                     
                       
      validate(need(is.numeric(ANL[[dist_var]]), "Please select a numeric variable."))
- 627 + 632 !
      teal::validate_has_data(ANL, 1, complete = TRUE)
- 628 + 633

                     
                   
                   
-                    629
+                    634
                     !
                     
                       
      if (length(t_dist) != 0) {
- 630 + 635 !
        map_distr_nams <- list(
- 631 + 636 !
          normal = c("mean", "sd"),
- 632 + 637 !
          lognormal = c("meanlog", "sdlog"),
- 633 + 638 !
          gamma = c("shape", "rate"),
- 634 + 639 !
          unif = c("min", "max")
- 635 + 640
        )
- 636 + 641 !
        params_names_raw <- map_distr_nams[[t_dist]]
- 637 + 642

                     
                   
                   
-                    638
+                    643
                     !
                     
                       
        qenv <- teal.code::eval_code(
- 639 + 644 !
          qenv,
- 640 + 645 !
          substitute(
- 641 + 646 !
            expr = {
- 642 + 647 !
              params <- as.list(c(dist_param1, dist_param2))
- 643 + 648 !
              names(params) <- params_names_raw
- 644 + 649
            },
- 645 + 650 !
            env = list(
- 646 + 651 !
              dist_param1 = dist_param1,
- 647 + 652 !
              dist_param2 = dist_param2,
- 648 + 653 !
              params_names_raw = params_names_raw
- 649 + 654
            )
- 650 + 655
          )
- 651 + 656
        )
- 652 + 657
      }
- 653 + 658

                     
                   
                   
-                    654
+                    659
                     !
                     
                       
      if (length(s_var) == 0 && length(g_var) == 0) {
- 655 + 660 !
        qenv <- teal.code::eval_code(
- 656 + 661 !
          qenv,
- 657 + 662 !
          substitute(
- 658 + 663 !
            expr = {
- 659 + 664 !
              summary_table <- ANL %>%
- 660 + 665 !
                dplyr::summarise(
- 661 + 666 !
                  min = round(min(dist_var_name, na.rm = TRUE), roundn),
- 662 + 667 !
                  median = round(stats::median(dist_var_name, na.rm = TRUE), roundn),
- 663 + 668 !
                  mean = round(mean(dist_var_name, na.rm = TRUE), roundn),
- 664 + 669 !
                  max = round(max(dist_var_name, na.rm = TRUE), roundn),
- 665 + 670 !
                  sd = round(stats::sd(dist_var_name, na.rm = TRUE), roundn),
- 666 + 671 !
                  count = dplyr::n()
- 667 + 672
                )
- 668 + 673
            },
- 669 + 674 !
            env = list(
- 670 + 675 !
              dist_var_name = as.name(dist_var),
- 671 + 676 !
              roundn = roundn
- 672 + 677
            )
- 673 + 678
          )
- 674 + 679
        )
- 675 + 680
      } else {
- 676 + 681 !
        qenv <- teal.code::eval_code(
- 677 + 682 !
          qenv,
- 678 + 683 !
          substitute(
- 679 + 684 !
            expr = {
- 680 + 685 !
              strata_vars <- strata_vars_raw
- 681 + 686 !
              summary_table <- ANL %>%
- 682 + 687 !
                dplyr::group_by_at(dplyr::vars(dplyr::any_of(strata_vars))) %>%
- 683 + 688 !
                dplyr::summarise(
- 684 + 689 !
                  min = round(min(dist_var_name, na.rm = TRUE), roundn),
- 685 + 690 !
                  median = round(stats::median(dist_var_name, na.rm = TRUE), roundn),
- 686 + 691 !
                  mean = round(mean(dist_var_name, na.rm = TRUE), roundn),
- 687 + 692 !
                  max = round(max(dist_var_name, na.rm = TRUE), roundn),
- 688 + 693 !
                  sd = round(stats::sd(dist_var_name, na.rm = TRUE), roundn),
- 689 + 694 !
                  count = dplyr::n()
- 690 + 695
                )
- 691 + 696 !
              summary_table # used to display table when running show-r-code code
- 692 + 697
            },
- 693 + 698 !
            env = list(
- 694 + 699 !
              dist_var_name = dist_var_name,
- 695 + 700 !
              strata_vars_raw = c(g_var, s_var),
- 696 + 701 !
              roundn = roundn
- 697 + 702
            )
- 698 + 703
          )
- 699 + 704
        )
- 700 + 705
      }
- 701 + 706
    })
- 702 + 707

                     
                   
                   
-                    703
+                    708
                     
                     
                       
    # distplot qenv ----
- 704 + 709 !
    dist_q <- eventReactive(
- 705 + 710 !
      eventExpr = {
- 706 + 711 !
        common_q()
- 707 + 712 !
        input$scales_type
- 708 + 713 !
        input$main_type
- 709 + 714 !
        input$bins
- 710 + 715 !
        input$add_dens
- 711 + 716 !
        is.null(input$ggtheme)
- 712 + 717
      },
- 713 + 718 !
      valueExpr = {
- 714 + 719 !
        dist_var <- merge_vars()$dist_var
- 715 + 720 !
        s_var <- merge_vars()$s_var
- 716 + 721 !
        g_var <- merge_vars()$g_var
- 717 + 722 !
        dist_var_name <- merge_vars()$dist_var_name
- 718 + 723 !
        s_var_name <- merge_vars()$s_var_name
- 719 + 724 !
        g_var_name <- merge_vars()$g_var_name
- 720 + 725 !
        t_dist <- input$t_dist
- 721 + 726 !
        dist_param1 <- input$dist_param1
- 722 + 727 !
        dist_param2 <- input$dist_param2
- 723 + 728

                     
                   
                   
-                    724
+                    729
                     !
                     
                       
        scales_type <- input$scales_type
- 725 + 730

                     
                   
                   
-                    726
+                    731
                     !
                     
                       
        ndensity <- 512
- 727 + 732 !
        main_type_var <- input$main_type
- 728 + 733 !
        bins_var <- input$bins
- 729 + 734 !
        add_dens_var <- input$add_dens
- 730 + 735 !
        ggtheme <- input$ggtheme
- 731 + 736

                     
                   
                   
-                    732
+                    737
                     !
                     
                       
        teal::validate_inputs(iv_dist)
- 733 + 738

                     
                   
                   
-                    734
+                    739
                     !
                     
                       
        qenv <- common_q()
- 735 + 740

                     
                   
                   
-                    736
+                    741
                     !
                     
                       
        m_type <- if (main_type_var == "Density") "density" else "count"
- 737 + 742

                     
                   
                   
-                    738
+                    743
                     !
                     
                       
        plot_call <- if (length(s_var) == 0 && length(g_var) == 0) {
- 739 + 744 !
          substitute(
- 740 + 745 !
            expr = ggplot(ANL, aes(dist_var_name)) +
- 741 + 746 !
              geom_histogram(
- 742 + 747 !
                position = "identity", aes(y = after_stat(m_type)), bins = bins_var, alpha = 0.3
- 743 + 748
              ),
- 744 + 749 !
            env = list(
- 745 + 750 !
              m_type = as.name(m_type), bins_var = bins_var, dist_var_name = as.name(dist_var)
- 746 + 751
            )
- 747 + 752
          )
- 748 + 753 !
        } else if (length(s_var) != 0 && length(g_var) == 0) {
- 749 + 754 !
          substitute(
- 750 + 755 !
            expr = ggplot(ANL, aes(dist_var_name, col = s_var_name)) +
- 751 + 756 !
              geom_histogram(
- 752 + 757 !
                position = "identity", aes(y = after_stat(m_type), fill = s_var), bins = bins_var, alpha = 0.3
- 753 + 758
              ),
- 754 + 759 !
            env = list(
- 755 + 760 !
              m_type = as.name(m_type),
- 756 + 761 !
              bins_var = bins_var,
- 757 + 762 !
              dist_var_name = dist_var_name,
- 758 + 763 !
              s_var = as.name(s_var),
- 759 + 764 !
              s_var_name = s_var_name
- 760 + 765
            )
- 761 + 766
          )
- 762 + 767 !
        } else if (length(s_var) == 0 && length(g_var) != 0) {
- 763 + 768 !
          req(scales_type)
- 764 + 769 !
          substitute(
- 765 + 770 !
            expr = ggplot(ANL[ANL[[g_var]] != "NA", ], aes(dist_var_name)) +
- 766 + 771 !
              geom_histogram(
- 767 + 772 !
                position = "identity", aes(y = after_stat(m_type)), bins = bins_var, alpha = 0.3
- 768 + 773
              ) +
- 769 + 774 !
              facet_wrap(~g_var_name, ncol = 1, scales = scales_raw),
- 770 + 775 !
            env = list(
- 771 + 776 !
              m_type = as.name(m_type),
- 772 + 777 !
              bins_var = bins_var,
- 773 + 778 !
              dist_var_name = dist_var_name,
- 774 + 779 !
              g_var = g_var,
- 775 + 780 !
              g_var_name = g_var_name,
- 776 + 781 !
              scales_raw = tolower(scales_type)
- 777 + 782
            )
- 778 + 783
          )
- 779 + 784
        } else {
- 780 + 785 !
          req(scales_type)
- 781 + 786 !
          substitute(
- 782 + 787 !
            expr = ggplot(ANL[ANL[[g_var]] != "NA", ], aes(dist_var_name, col = s_var_name)) +
- 783 + 788 !
              geom_histogram(
- 784 + 789 !
                position = "identity",
- 785 + 790 !
                aes(y = after_stat(m_type), fill = s_var), bins = bins_var, alpha = 0.3
- 786 + 791
              ) +
- 787 + 792 !
              facet_wrap(~g_var_name, ncol = 1, scales = scales_raw),
- 788 + 793 !
            env = list(
- 789 + 794 !
              m_type = as.name(m_type),
- 790 + 795 !
              bins_var = bins_var,
- 791 + 796 !
              dist_var_name = dist_var_name,
- 792 + 797 !
              g_var = g_var,
- 793 + 798 !
              s_var = as.name(s_var),
- 794 + 799 !
              g_var_name = g_var_name,
- 795 + 800 !
              s_var_name = s_var_name,
- 796 + 801 !
              scales_raw = tolower(scales_type)
- 797 + 802
            )
- 798 + 803
          )
- 799 + 804
        }
- 800 + 805

                     
                   
                   
-                    801
+                    806
                     !
                     
                       
        if (add_dens_var) {
- 802 + 807 !
          plot_call <- substitute(
- 803 + 808 !
            expr = plot_call +
- 804 + 809 !
              stat_density(
- 805 + 810 !
                aes(y = after_stat(const * m_type2)),
- 806 + 811 !
                geom = "line",
- 807 + 812 !
                position = "identity",
- 808 + 813 !
                alpha = 0.5,
- 809 + 814 !
                size = 2,
- 810 + 815 !
                n = ndensity
- 811 + 816
              ),
- 812 + 817 !
            env = list(
- 813 + 818 !
              plot_call = plot_call,
- 814 + 819 !
              const = if (main_type_var == "Density") {
- 815 + 820 !
                1
- 816 + 821
              } else {
- 817 + 822 !
                diff(range(qenv[["ANL"]][[dist_var]], na.rm = TRUE)) / bins_var
- 818 + 823
              },
- 819 + 824 !
              m_type2 = if (main_type_var == "Density") as.name("density") else as.name("count"),
- 820 + 825 !
              ndensity = ndensity
- 821 + 826
            )
- 822 + 827
          )
- 823 + 828
        }
- 824 + 829

                     
                   
                   
-                    825
+                    830
                     !
                     
                       
        if (length(t_dist) != 0 && main_type_var == "Density" && length(g_var) == 0 && length(s_var) == 0) {
- 826 + 831 !
          qenv <- teal.code::eval_code(
- 827 + 832 !
            qenv,
- 828 + 833 !
            substitute(
- 829 + 834 !
              df_params <- as.data.frame(append(params, list(name = t_dist))),
- 830 + 835 !
              env = list(t_dist = t_dist)
- 831 + 836
            )
- 832 + 837
          )
- 833 + 838 !
          datas <- quote(data.frame(x = 0.7, y = 1, tb = I(list(df_params = df_params))))
- 834 + 839 !
          label <- quote(tb)
- 835 + 840

                     
                   
                   
-                    836
+                    841
                     !
                     
                       
          plot_call <- substitute(
- 837 + 842 !
            expr = plot_call + ggpp::geom_table_npc(
- 838 + 843 !
              data = data,
- 839 + 844 !
              aes(npcx = x, npcy = y, label = label),
- 840 + 845 !
              hjust = 0, vjust = 1, size = 4
- 841 + 846
            ),
- 842 + 847 !
            env = list(plot_call = plot_call, data = datas, label = label)
- 843 + 848
          )
- 844 + 849
        }
- 845 + 850

                     
                   
                   
-                    846
+                    851
                     !
                     
                       
        if (
- 847 + 852 !
          length(s_var) == 0 &&
- 848 + 853 !
            length(g_var) == 0 &&
- 849 + 854 !
            main_type_var == "Density" &&
- 850 + 855 !
            length(t_dist) != 0 &&
- 851 + 856 !
            main_type_var == "Density"
- 852 + 857
        ) {
- 853 + 858 !
          map_dist <- stats::setNames(
- 854 + 859 !
            c("dnorm", "dlnorm", "dgamma", "dunif"),
- 855 + 860 !
            c("normal", "lognormal", "gamma", "unif")
- 856 + 861
          )
- 857 + 862 !
          plot_call <- substitute(
- 858 + 863 !
            expr = plot_call + stat_function(
- 859 + 864 !
              data = data.frame(x = range(ANL[[dist_var]]), color = mapped_dist),
- 860 + 865 !
              aes(x, color = color),
- 861 + 866 !
              fun = mapped_dist_name,
- 862 + 867 !
              n = ndensity,
- 863 + 868 !
              size = 2,
- 864 + 869 !
              args = params
- 865 + 870
            ) +
- 866 + 871 !
              scale_color_manual(values = stats::setNames("blue", mapped_dist), aesthetics = "color"),
- 867 + 872 !
            env = list(
- 868 + 873 !
              plot_call = plot_call,
- 869 + 874 !
              dist_var = dist_var,
- 870 + 875 !
              ndensity = ndensity,
- 871 + 876 !
              mapped_dist = unname(map_dist[t_dist]),
- 872 + 877 !
              mapped_dist_name = as.name(unname(map_dist[t_dist]))
- 873 + 878
            )
- 874 + 879
          )
- 875 + 880
        }
- 876 + 881

                     
                   
                   
-                    877
+                    882
                     !
                     
                       
        all_ggplot2_args <- teal.widgets::resolve_ggplot2_args(
- 878 + 883 !
          user_plot = ggplot2_args[["Histogram"]],
- 879 + 884 !
          user_default = ggplot2_args$default
- 880 + 885
        )
- 881 + 886

                     
                   
                   
-                    882
+                    887
                     !
                     
                       
        parsed_ggplot2_args <- teal.widgets::parse_ggplot2_args(
- 883 + 888 !
          all_ggplot2_args,
- 884 + 889 !
          ggtheme = ggtheme
- 885 + 890
        )
- 886 + 891

                     
                   
                   
-                    887
+                    892
                     !
                     
                       
        teal.code::eval_code(
- 888 + 893 !
          qenv,
- 889 + 894 !
          substitute(
- 890 + 895 !
            expr = {
- 891 + 896 !
              g <- plot_call
- 892 + 897 !
              print(g)
- 893 + 898
            },
- 894 + 899 !
            env = list(plot_call = Reduce(function(x, y) call("+", x, y), c(plot_call, parsed_ggplot2_args)))
- 895 + 900
          )
- 896 + 901
        )
- 897 + 902
      }
- 898 + 903
    )
- 899 + 904

                     
                   
                   
-                    900
+                    905
                     
                     
                       
    # qqplot qenv ----
- 901 + 906 !
    qq_q <- eventReactive(
- 902 + 907 !
      eventExpr = {
- 903 + 908 !
        common_q()
- 904 + 909 !
        input$scales_type
- 905 + 910 !
        input$qq_line
- 906 + 911 !
        is.null(input$ggtheme)
- 907 + 912
      },
- 908 + 913 !
      valueExpr = {
- 909 + 914 !
        dist_var <- merge_vars()$dist_var
- 910 + 915 !
        s_var <- merge_vars()$s_var
- 911 + 916 !
        g_var <- merge_vars()$g_var
- 912 + 917 !
        dist_var_name <- merge_vars()$dist_var_name
- 913 + 918 !
        s_var_name <- merge_vars()$s_var_name
- 914 + 919 !
        g_var_name <- merge_vars()$g_var_name
- 915 + 920 !
        t_dist <- input$t_dist
- 916 + 921 !
        dist_param1 <- input$dist_param1
- 917 + 922 !
        dist_param2 <- input$dist_param2
- 918 + 923

                     
                   
                   
-                    919
+                    924
                     !
                     
                       
        scales_type <- input$scales_type
- 920 + 925 !
        ggtheme <- input$ggtheme
- 921 + 926

                     
                   
                   
-                    922
+                    927
                     !
                     
                       
        teal::validate_inputs(iv_r_dist(), iv_dist)
- 923 + 928

                     
                   
                   
-                    924
+                    929
                     !
                     
                       
        qenv <- common_q()
- 925 + 930

                     
                   
                   
-                    926
+                    931
                     !
                     
                       
        plot_call <- if (length(s_var) == 0 && length(g_var) == 0) {
- 927 + 932 !
          substitute(
- 928 + 933 !
            expr = ggplot(ANL, aes_string(sample = dist_var)),
- 929 + 934 !
            env = list(dist_var = dist_var)
- 930 + 935
          )
- 931 + 936 !
        } else if (length(s_var) != 0 && length(g_var) == 0) {
- 932 + 937 !
          substitute(
- 933 + 938 !
            expr = ggplot(ANL, aes_string(sample = dist_var, color = s_var)),
- 934 + 939 !
            env = list(dist_var = dist_var, s_var = s_var)
- 935 + 940
          )
- 936 + 941 !
        } else if (length(s_var) == 0 && length(g_var) != 0) {
- 937 + 942 !
          substitute(
- 938 + 943 !
            expr = ggplot(ANL[ANL[[g_var]] != "NA", ], aes_string(sample = dist_var)) +
- 939 + 944 !
              facet_wrap(~g_var_name, ncol = 1, scales = scales_raw),
- 940 + 945 !
            env = list(
- 941 + 946 !
              dist_var = dist_var,
- 942 + 947 !
              g_var = g_var,
- 943 + 948 !
              g_var_name = g_var_name,
- 944 + 949 !
              scales_raw = tolower(scales_type)
- 945 + 950
            )
- 946 + 951
          )
- 947 + 952
        } else {
- 948 + 953 !
          substitute(
- 949 + 954 !
            expr = ggplot(ANL[ANL[[g_var]] != "NA", ], aes_string(sample = dist_var, color = s_var)) +
- 950 + 955 !
              facet_wrap(~g_var_name, ncol = 1, scales = scales_raw),
- 951 + 956 !
            env = list(
- 952 + 957 !
              dist_var = dist_var,
- 953 + 958 !
              g_var = g_var,
- 954 + 959 !
              s_var = s_var,
- 955 + 960 !
              g_var_name = g_var_name,
- 956 + 961 !
              scales_raw = tolower(scales_type)
- 957 + 962
            )
- 958 + 963
          )
- 959 + 964
        }
- 960 + 965

                     
                   
                   
-                    961
+                    966
                     !
                     
                       
        map_dist <- stats::setNames(
- 962 + 967 !
          c("qnorm", "qlnorm", "qgamma", "qunif"),
- 963 + 968 !
          c("normal", "lognormal", "gamma", "unif")
- 964 + 969
        )
- 965 + 970

                     
                   
                   
-                    966
+                    971
                     !
                     
                       
        plot_call <- substitute(
- 967 + 972 !
          expr = plot_call +
- 968 + 973 !
            stat_qq(distribution = mapped_dist, dparams = params),
- 969 + 974 !
          env = list(plot_call = plot_call, mapped_dist = as.name(unname(map_dist[t_dist])))
- 970 + 975
        )
- 971 + 976

                     
                   
                   
-                    972
+                    977
                     !
                     
                       
        if (length(t_dist) != 0 && length(g_var) == 0 && length(s_var) == 0) {
- 973 + 978 !
          qenv <- teal.code::eval_code(
- 974 + 979 !
            qenv,
- 975 + 980 !
            substitute(
- 976 + 981 !
              df_params <- as.data.frame(append(params, list(name = t_dist))),
- 977 + 982 !
              env = list(t_dist = t_dist)
- 978 + 983
            )
- 979 + 984
          )
- 980 + 985 !
          datas <- quote(data.frame(x = 0.7, y = 1, tb = I(list(df_params = df_params))))
- 981 + 986 !
          label <- quote(tb)
- 982 + 987

                     
                   
                   
-                    983
+                    988
                     !
                     
                       
          plot_call <- substitute(
- 984 + 989 !
            expr = plot_call +
- 985 + 990 !
              ggpp::geom_table_npc(
- 986 + 991 !
                data = data,
- 987 + 992 !
                aes(npcx = x, npcy = y, label = label),
- 988 + 993 !
                hjust = 0,
- 989 + 994 !
                vjust = 1,
- 990 + 995 !
                size = 4
- 991 + 996
              ),
- 992 + 997 !
            env = list(
- 993 + 998 !
              plot_call = plot_call,
- 994 + 999 !
              data = datas,
- 995 + 1000 !
              label = label
- 996 + 1001
            )
- 997 + 1002
          )
- 998 + 1003
        }
- 999 + 1004

                     
                   
                   
-                    1000
+                    1005
                     !
                     
                       
        if (isTRUE(input$qq_line)) {
- 1001 + 1006 !
          plot_call <- substitute(
- 1002 + 1007 !
            expr = plot_call +
- 1003 + 1008 !
              stat_qq_line(distribution = mapped_dist, dparams = params),
- 1004 + 1009 !
            env = list(plot_call = plot_call, mapped_dist = as.name(unname(map_dist[t_dist])))
- 1005 + 1010
          )
- 1006 + 1011
        }
- 1007 + 1012

                     
                   
                   
-                    1008
+                    1013
                     !
                     
                       
        all_ggplot2_args <- teal.widgets::resolve_ggplot2_args(
- 1009 + 1014 !
          user_plot = ggplot2_args[["QQplot"]],
- 1010 + 1015 !
          user_default = ggplot2_args$default,
- 1011 + 1016 !
          module_plot = teal.widgets::ggplot2_args(labs = list(x = "theoretical", y = "sample"))
- 1012 + 1017
        )
- 1013 + 1018

                     
                   
                   
-                    1014
+                    1019
                     !
                     
                       
        parsed_ggplot2_args <- teal.widgets::parse_ggplot2_args(
- 1015 + 1020 !
          all_ggplot2_args,
- 1016 + 1021 !
          ggtheme = ggtheme
- 1017 + 1022
        )
- 1018 + 1023

                     
                   
                   
-                    1019
+                    1024
                     !
                     
                       
        teal.code::eval_code(
- 1020 + 1025 !
          qenv,
- 1021 + 1026 !
          substitute(
- 1022 + 1027 !
            expr = {
- 1023 + 1028 !
              g <- plot_call
- 1024 + 1029 !
              print(g)
- 1025 + 1030
            },
- 1026 + 1031 !
            env = list(plot_call = Reduce(function(x, y) call("+", x, y), c(plot_call, parsed_ggplot2_args)))
- 1027 + 1032
          )
- 1028 + 1033
        )
- 1029 + 1034
      }
- 1030 + 1035
    )
- 1031 + 1036

                     
                   
                   
-                    1032
+                    1037
                     
                     
                       
    # test qenv ----
- 1033 + 1038 !
    test_q <- eventReactive(
- 1034 + 1039 !
      ignoreNULL = FALSE,
- 1035 + 1040 !
      eventExpr = {
- 1036 + 1041 !
        common_q()
- 1037 + 1042 !
        input$dist_param1
- 1038 + 1043 !
        input$dist_param2
- 1039 + 1044 !
        input$dist_tests
- 1040 + 1045
      },
- 1041 + 1046 !
      valueExpr = {
- 1042 + 1047
        # Create a private stack for this function only.
- 1043 + 1048 !
        ANL <- common_q()[["ANL"]]
- 1044 + 1049

                     
                   
                   
-                    1045
+                    1050
                     !
                     
                       
        dist_var <- merge_vars()$dist_var
- 1046 + 1051 !
        s_var <- merge_vars()$s_var
- 1047 + 1052 !
        g_var <- merge_vars()$g_var
- 1048 + 1053

                     
                   
                   
-                    1049
+                    1054
                     !
                     
                       
        dist_var_name <- merge_vars()$dist_var_name
- 1050 + 1055 !
        s_var_name <- merge_vars()$s_var_name
- 1051 + 1056 !
        g_var_name <- merge_vars()$g_var_name
- 1052 + 1057

                     
                   
                   
-                    1053
+                    1058
                     !
                     
                       
        dist_param1 <- input$dist_param1
- 1054 + 1059 !
        dist_param2 <- input$dist_param2
- 1055 + 1060 !
        dist_tests <- input$dist_tests
- 1056 + 1061 !
        t_dist <- input$t_dist
- 1057 + 1062

                     
                   
                   
-                    1058
+                    1063
                     !
                     
                       
        validate(need(dist_tests, "Please select a test"))
- 1059 + 1064

                     
                   
                   
-                    1060
+                    1065
                     !
                     
                       
        teal::validate_inputs(iv_dist)
- 1061 + 1066

                     
                   
                   
-                    1062
+                    1067
                     !
                     
                       
        if (length(s_var) > 0 || length(g_var) > 0) {
- 1063 + 1068 !
          counts <- ANL %>%
- 1064 + 1069 !
            dplyr::group_by_at(dplyr::vars(dplyr::any_of(c(s_var, g_var)))) %>%
- 1065 + 1070 !
            dplyr::summarise(n = dplyr::n())
- 1066 + 1071

                     
                   
                   
-                    1067
+                    1072
                     !
                     
                       
          validate(need(all(counts$n > 5), "Please select strata*group with at least 5 observation each."))
- 1068 + 1073
        }
- 1069 + 1074

                     
                   
                   
-                    1070
+                    1075
                     
                     
                       

                     
                   
                   
-                    1071
+                    1076
                     !
                     
                       
        if (dist_tests %in% c(
- 1072 + 1077 !
          "t-test (two-samples, not paired)",
- 1073 + 1078 !
          "F-test",
- 1074 + 1079 !
          "Kolmogorov-Smirnov (two-samples)"
- 1075 + 1080
        )) {
- 1076 + 1081 !
          if (length(g_var) == 0 && length(s_var) > 0) {
- 1077 + 1082 !
            validate(need(
- 1078 + 1083 !
              length(unique(ANL[[s_var]])) == 2,
- 1079 + 1084 !
              "Please select stratify variable with 2 levels."
- 1080 + 1085
            ))
- 1081 + 1086
          }
- 1082 + 1087 !
          if (length(g_var) > 0 && length(s_var) > 0) {
- 1083 + 1088 !
            validate(need(
- 1084 + 1089 !
              all(stats::na.omit(as.vector(
- 1085 + 1090 !
                tapply(ANL[[s_var]], list(ANL[[g_var]]), function(x) length(unique(x))) == 2
- 1086 + 1091
              ))),
- 1087 + 1092 !
              "Please select stratify variable with 2 levels, per each group."
- 1088 + 1093
            ))
- 1089 + 1094
          }
- 1090 + 1095
        }
- 1091 + 1096

                     
                   
                   
-                    1092
+                    1097
                     !
                     
                       
        map_dist <- stats::setNames(
- 1093 + 1098 !
          c("pnorm", "plnorm", "pgamma", "punif"),
- 1094 + 1099 !
          c("normal", "lognormal", "gamma", "unif")
- 1095 + 1100
        )
- 1096 + 1101 !
        sks_args <- list(
- 1097 + 1102 !
          test = quote(stats::ks.test),
- 1098 + 1103 !
          args = bquote(append(list(.[[.(dist_var)]], .(map_dist[t_dist])), params)),
- 1099 + 1104 !
          groups = c(g_var, s_var)
- 1100 + 1105
        )
- 1101 + 1106 !
        ssw_args <- list(
- 1102 + 1107 !
          test = quote(stats::shapiro.test),
- 1103 + 1108 !
          args = bquote(list(.[[.(dist_var)]])),
- 1104 + 1109 !
          groups = c(g_var, s_var)
- 1105 + 1110
        )
- 1106 + 1111 !
        mfil_args <- list(
- 1107 + 1112 !
          test = quote(stats::fligner.test),
- 1108 + 1113 !
          args = bquote(list(.[[.(dist_var)]], .[[.(s_var)]])),
- 1109 + 1114 !
          groups = c(g_var)
- 1110 + 1115
        )
- 1111 + 1116 !
        sad_args <- list(
- 1112 + 1117 !
          test = quote(goftest::ad.test),
- 1113 + 1118 !
          args = bquote(append(list(.[[.(dist_var)]], .(map_dist[t_dist])), params)),
- 1114 + 1119 !
          groups = c(g_var, s_var)
- 1115 + 1120
        )
- 1116 + 1121 !
        scvm_args <- list(
- 1117 + 1122 !
          test = quote(goftest::cvm.test),
- 1118 + 1123 !
          args = bquote(append(list(.[[.(dist_var)]], .(map_dist[t_dist])), params)),
- 1119 + 1124 !
          groups = c(g_var, s_var)
- 1120 + 1125
        )
- 1121 + 1126 !
        manov_args <- list(
- 1122 + 1127 !
          test = quote(stats::aov),
- 1123 + 1128 !
          args = bquote(list(stats::formula(.(dist_var_name) ~ .(s_var_name)), .)),
- 1124 + 1129 !
          groups = c(g_var)
- 1125 + 1130
        )
- 1126 + 1131 !
        mt_args <- list(
- 1127 + 1132 !
          test = quote(stats::t.test),
- 1128 + 1133 !
          args = bquote(unname(split(.[[.(dist_var)]], .[[.(s_var)]], drop = TRUE))),
- 1129 + 1134 !
          groups = c(g_var)
- 1130 + 1135
        )
- 1131 + 1136 !
        mv_args <- list(
- 1132 + 1137 !
          test = quote(stats::var.test),
- 1133 + 1138 !
          args = bquote(unname(split(.[[.(dist_var)]], .[[.(s_var)]], drop = TRUE))),
- 1134 + 1139 !
          groups = c(g_var)
- 1135 + 1140
        )
- 1136 + 1141 !
        mks_args <- list(
- 1137 + 1142 !
          test = quote(stats::ks.test),
- 1138 + 1143 !
          args = bquote(unname(split(.[[.(dist_var)]], .[[.(s_var)]], drop = TRUE))),
- 1139 + 1144 !
          groups = c(g_var)
- 1140 + 1145
        )
- 1141 + 1146

                     
                   
                   
-                    1142
+                    1147
                     !
                     
                       
        tests_base <- switch(dist_tests,
- 1143 + 1148 !
          "Kolmogorov-Smirnov (one-sample)" = sks_args,
- 1144 + 1149 !
          "Shapiro-Wilk" = ssw_args,
- 1145 + 1150 !
          "Fligner-Killeen" = mfil_args,
- 1146 + 1151 !
          "one-way ANOVA" = manov_args,
- 1147 + 1152 !
          "t-test (two-samples, not paired)" = mt_args,
- 1148 + 1153 !
          "F-test" = mv_args,
- 1149 + 1154 !
          "Kolmogorov-Smirnov (two-samples)" = mks_args,
- 1150 + 1155 !
          "Anderson-Darling (one-sample)" = sad_args,
- 1151 + 1156 !
          "Cramer-von Mises (one-sample)" = scvm_args
- 1152 + 1157
        )
- 1153 + 1158

                     
                   
                   
-                    1154
+                    1159
                     !
                     
                       
        env <- list(
- 1155 + 1160 !
          t_test = t_dist,
- 1156 + 1161 !
          dist_var = dist_var,
- 1157 + 1162 !
          g_var = g_var,
- 1158 + 1163 !
          s_var = s_var,
- 1159 + 1164 !
          args = tests_base$args,
- 1160 + 1165 !
          groups = tests_base$groups,
- 1161 + 1166 !
          test = tests_base$test,
- 1162 + 1167 !
          dist_var_name = dist_var_name,
- 1163 + 1168 !
          g_var_name = g_var_name,
- 1164 + 1169 !
          s_var_name = s_var_name
- 1165 + 1170
        )
- 1166 + 1171

                     
                   
                   
-                    1167
+                    1172
                     !
                     
                       
        qenv <- common_q()
- 1168 + 1173

                     
                   
                   
-                    1169
+                    1174
                     !
                     
                       
        if (length(s_var) == 0 && length(g_var) == 0) {
- 1170 + 1175 !
          qenv <- teal.code::eval_code(
- 1171 + 1176 !
            qenv,
- 1172 + 1177 !
            substitute(
- 1173 + 1178 !
              expr = {
- 1174 + 1179 !
                test_stats <- ANL %>%
- 1175 + 1180 !
                  dplyr::select(dist_var) %>%
- 1176 + 1181 !
                  with(., broom::glance(do.call(test, args))) %>%
- 1177 + 1182 !
                  dplyr::mutate_if(is.numeric, round, 3)
- 1178 + 1183
              },
- 1179 + 1184 !
              env = env
- 1180 + 1185
            )
- 1181 + 1186
          )
- 1182 + 1187
        } else {
- 1183 + 1188 !
          qenv <- teal.code::eval_code(
- 1184 + 1189 !
            qenv,
- 1185 + 1190 !
            substitute(
- 1186 + 1191 !
              expr = {
- 1187 + 1192 !
                test_stats <- ANL %>%
- 1188 + 1193 !
                  dplyr::select(dist_var, s_var, g_var) %>%
- 1189 + 1194 !
                  dplyr::group_by_at(dplyr::vars(dplyr::any_of(groups))) %>%
- 1190 + 1195 !
                  dplyr::do(tests = broom::glance(do.call(test, args))) %>%
- 1191 + 1196 !
                  tidyr::unnest(tests) %>%
- 1192 + 1197 !
                  dplyr::mutate_if(is.numeric, round, 3)
- 1193 + 1198
              },
- 1194 + 1199 !
              env = env
- 1195 + 1200
            )
- 1196 + 1201
          )
- 1197 + 1202
        }
- 1198 + 1203 !
        qenv %>%
- 1199 + 1204
          # used to display table when running show-r-code code
- 1200 + 1205 !
          teal.code::eval_code(quote(test_stats))
- 1201 + 1206
      }
- 1202 + 1207
    )
- 1203 + 1208

                     
                   
                   
-                    1204
+                    1209
                     
                     
                       
    # outputs ----
- 1205 + 1210
    ## building main qenv
- 1206 + 1211 !
    output_q <- reactive({
- 1207 + 1212 !
      tab <- input$tabs
- 1208 + 1213 !
      req(tab) # tab is NULL upon app launch, hence will crash without this statement
- 1209 + 1214

                     
                   
                   
-                    1210
+                    1215
                     !
                     
                       
      qenv_final <- common_q()
- 1211 + 1216
      # wrapped in if since could lead into validate error - we do want to continue
- 1212 + 1217 !
      test_r_qenv_out <- try(test_q(), silent = TRUE)
- 1213 + 1218 !
      if (!inherits(test_r_qenv_out, c("try-error", "error"))) {
- 1214 + 1219 !
        qenv_final <- teal.code::join(qenv_final, test_q())
- 1215 + 1220
      }
- 1216 + 1221

                     
                   
                   
-                    1217
+                    1222
                     !
                     
                       
      qenv_final <- if (tab == "Histogram") {
- 1218 + 1223 !
        req(dist_q())
- 1219 + 1224 !
        teal.code::join(qenv_final, dist_q())
- 1220 + 1225 !
      } else if (tab == "QQplot") {
- 1221 + 1226 !
        req(qq_q())
- 1222 + 1227 !
        teal.code::join(qenv_final, qq_q())
- 1223 + 1228
      }
- 1224 + 1229 !
      qenv_final
- 1225 + 1230
    })
- 1226 + 1231

                     
                   
                   
-                    1227
+                    1232
                     !
                     
                       
    dist_r <- reactive(dist_q()[["g"]])
- 1228 + 1233

                     
                   
                   
-                    1229
+                    1234
                     !
                     
                       
    qq_r <- reactive(qq_q()[["g"]])
- 1230 + 1235

                     
                   
                   
-                    1231
+                    1236
                     !
                     
                       
    output$summary_table <- DT::renderDataTable(
- 1232 + 1237 !
      expr = if (iv_r()$is_valid()) common_q()[["summary_table"]] else NULL,
- 1233 + 1238 !
      options = list(
- 1234 + 1239 !
        autoWidth = TRUE,
- 1235 + 1240 !
        columnDefs = list(list(width = "200px", targets = "_all"))
- 1236 + 1241
      ),
- 1237 + 1242 !
      rownames = FALSE
- 1238 + 1243
    )
- 1239 + 1244

                     
                   
                   
-                    1240
+                    1245
                     !
                     
                       
    tests_r <- reactive({
- 1241 + 1246 !
      req(iv_r()$is_valid())
- 1242 + 1247 !
      teal::validate_inputs(iv_r_dist())
- 1243 + 1248 !
      test_q()[["test_stats"]]
- 1244 + 1249
    })
- 1245 + 1250

                     
                   
                   
-                    1246
+                    1251
                     !
                     
                       
    pws1 <- teal.widgets::plot_with_settings_srv(
- 1247 + 1252 !
      id = "hist_plot",
- 1248 + 1253 !
      plot_r = dist_r,
- 1249 + 1254 !
      height = plot_height,
- 1250 + 1255 !
      width = plot_width,
- 1251 + 1256 !
      brushing = FALSE
- 1252 + 1257
    )
- 1253 + 1258

                     
                   
                   
-                    1254
+                    1259
                     !
                     
                       
    pws2 <- teal.widgets::plot_with_settings_srv(
- 1255 + 1260 !
      id = "qq_plot",
- 1256 + 1261 !
      plot_r = qq_r,
- 1257 + 1262 !
      height = plot_height,
- 1258 + 1263 !
      width = plot_width,
- 1259 + 1264 !
      brushing = FALSE
- 1260 + 1265
    )
- 1261 + 1266

                     
                   
                   
-                    1262
+                    1267
                     !
                     
                       
    output$t_stats <- DT::renderDataTable(
- 1263 + 1268 !
      expr = tests_r(),
- 1264 + 1269 !
      options = list(scrollX = TRUE),
- 1265 + 1270 !
      rownames = FALSE
- 1266 + 1271
    )
- 1267 + 1272

                     
                   
                   
-                    1268
+                    1273
                     !
                     
                       
    teal.widgets::verbatim_popup_srv(
- 1269 + 1274 !
      id = "rcode",
- 1270 + 1275 !
      verbatim_content = reactive(teal.code::get_code(output_q())),
- 1271 + 1276 !
      title = "R Code for distribution"
- 1272 + 1277
    )
- 1273 + 1278

                     
                   
                   
-                    1274
+                    1279
                     
                     
                       
    ### REPORTER
- 1275 + 1280 !
    if (with_reporter) {
- 1276 + 1281 !
      card_fun <- function(comment, label) {
- 1277 + 1282 !
        card <- teal::report_card_template(
- 1278 + 1283 !
          title = "Distribution Plot",
- 1279 + 1284 !
          label = label,
- 1280 + 1285 !
          with_filter = with_filter,
- 1281 + 1286 !
          filter_panel_api = filter_panel_api
- 1282 + 1287
        )
- 1283 + 1288 !
        card$append_text("Plot", "header3")
- 1284 + 1289 !
        if (input$tabs == "Histogram") {
- 1285 + 1290 !
          card$append_plot(dist_r(), dim = pws1$dim())
- 1286 + 1291 !
        } else if (input$tabs == "QQplot") {
- 1287 + 1292 !
          card$append_plot(qq_r(), dim = pws2$dim())
- 1288 + 1293
        }
- 1289 + 1294 !
        card$append_text("Statistics table", "header3")
- 1290 + 1295

                     
                   
                   
-                    1291
+                    1296
                     !
                     
                       
        card$append_table(common_q()[["summary_table"]])
- 1292 + 1297 !
        tests_error <- tryCatch(expr = tests_r(), error = function(e) "error")
- 1293 + 1298 !
        if (inherits(tests_error, "data.frame")) {
- 1294 + 1299 !
          card$append_text("Tests table", "header3")
- 1295 + 1300 !
          card$append_table(tests_r())
- 1296 + 1301
        }
- 1297 + 1302

                     
                   
                   
-                    1298
+                    1303
                     !
                     
                       
        if (!comment == "") {
- 1299 + 1304 !
          card$append_text("Comment", "header3")
- 1300 + 1305 !
          card$append_text(comment)
- 1301 + 1306
        }
- 1302 + 1307 !
        card$append_src(teal.code::get_code(output_q()))
- 1303 + 1308 !
        card
- 1304 + 1309
      }
- 1305 + 1310 !
      teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
- 1306 + 1311
    }
- 1307 + 1312
    ###
- 1308 + 1313
  })
- 1309 + 1314
}
@@ -9281,14 +9316,14 @@

teal.modules.general coverage - 3.44%

-