Skip to content

Commit

Permalink
tdata to teal_data - tm_outliers (#612)
Browse files Browse the repository at this point in the history
Example App

```
data <- teal_data()
data <- within(data, {
  ADSL <- teal.modules.general::rADSL
})
datanames <- c("ADSL")
datanames(data) <- datanames
join_keys(data) <- default_cdisc_join_keys[datanames]

fact_vars_adsl <- names(Filter(isTRUE, sapply(data[["ADSL"]], is.factor)))
vars <- choices_selected(variable_choices(data[["ADSL"]], fact_vars_adsl))

app <- teal::init(
  data = data,
  modules = teal::modules(
    teal.modules.general::tm_outliers(
      outlier_var = list(
        teal.transform::data_extract_spec(
          dataname = "ADSL",
          select = select_spec(
            label = "Select variable:",
            choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")),
            selected = "AGE",
            multiple = FALSE,
            fixed = FALSE
          )
        )
      ),
      categorical_var = list(
        teal.transform::data_extract_spec(
          dataname = "ADSL",
          filter = teal.transform::filter_spec(
            vars = vars,
            choices = value_choices(data[["ADSL"]], vars$selected),
            selected = value_choices(data[["ADSL"]], vars$selected),
            multiple = TRUE
          )
        )
      ),
      ggplot2_args = list(
        teal.widgets::ggplot2_args(
          labs = list(subtitle = "Plot generated by Outliers Module")
        )
      )
    )
  )
)

shinyApp(app$ui, app$server)
```
  • Loading branch information
kartikeyakirar authored Nov 23, 2023
1 parent dc5219d commit 2dde21d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions R/tm_outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
categorical_var, plot_height, plot_width, ggplot2_args) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "tdata")
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
vars <- list(outlier_var = outlier_var, categorical_var = categorical_var)

Expand Down Expand Up @@ -293,13 +294,12 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
anl_merged_input <- teal.transform::merge_expression_srv(
selector_list = reactive_select_input,
datasets = data,
join_keys = teal.data::join_keys(data),
merge_function = "dplyr::inner_join"
)

anl_merged_q <- reactive({
req(anl_merged_input())
teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data)) %>%
data() %>%
teal.code::eval_code(as.expression(anl_merged_input()$expr))
})

Expand All @@ -316,7 +316,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
})

# Used to create outlier table and the dropdown with additional columns
dataname_first <- names(data)[[1]]
dataname_first <- isolate(teal.data::datanames(data())[[1]])

common_code_q <- reactive({
shiny::req(iv_r()$is_valid())
Expand Down Expand Up @@ -476,7 +476,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
},
env = list(
dataname = as.name(dataname_first),
join_keys = as.character(teal.data::join_keys(data)[dataname_first, dataname_first])
join_keys = as.character(teal.data::join_keys(data())[dataname_first, dataname_first])
)
)
)
Expand Down Expand Up @@ -976,7 +976,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
brushing = TRUE
)

choices <- teal.transform::variable_choices(data[[dataname_first]]())
choices <- teal.transform::variable_choices(data()[[dataname_first]])

observeEvent(common_code_q(), {
ANL_OUTLIER <- common_code_q()[["ANL_OUTLIER"]] # nolint
Expand Down

0 comments on commit 2dde21d

Please sign in to comment.