Skip to content

Commit

Permalink
tdata to teal_data - tm_t_crosstable (#613)
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]

app <- teal::init(
  data = data,
  modules = teal::modules(
    teal.modules.general::tm_t_crosstable(
      label = "Cross Table",
      x = teal.transform::data_extract_spec(
        dataname = "ADSL",
        select = teal.transform::select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["ADSL"]], subset = function(data) {
            idx <- !vapply(data, inherits, logical(1), c("Date", "POSIXct", "POSIXlt"))
            return(names(data)[idx])
          }),
          selected = "COUNTRY",
          multiple = TRUE,
          ordered = TRUE,
          fixed = FALSE
        )
      ),
      y = teal.transform::data_extract_spec(
        dataname = "ADSL",
        select = teal.transform::select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["ADSL"]], subset = function(data) {
            idx <- vapply(data, is.factor, logical(1))
            return(names(data)[idx])
          }),
          selected = "SEX",
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      basic_table_args = teal.widgets::basic_table_args(
        subtitles = "Table generated by Crosstable Module"
      )
    )
  )
)

shinyApp(app$ui, app$server)
```
  • Loading branch information
kartikeyakirar authored Nov 23, 2023
1 parent 166b9a2 commit 522747b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions R/tm_t_crosstable.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ ui_t_crosstable <- function(id, x, y, show_percentage, show_total, pre_output, p
srv_t_crosstable <- function(id, data, reporter, filter_panel_api, label, x, y, basic_table_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) {
selector_list <- teal.transform::data_extract_multiple_srv(
data_extract = list(x = x, y = y),
Expand Down Expand Up @@ -215,14 +216,13 @@ srv_t_crosstable <- function(id, data, reporter, filter_panel_api, label, x, y,

anl_merged_input <- teal.transform::merge_expression_srv(
datasets = data,
join_keys = teal.data::join_keys(data),
selector_list = selector_list,
merge_function = merge_function
)

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 Down

0 comments on commit 522747b

Please sign in to comment.