Skip to contents

When method is defined for selected source, the output is displayed in attrition modal tab.

Usage

.custom_attrition(source, ...)

Arguments

source

Source object.

...

Extra arguments passed to specific method.

Value

List of two objects: `render` and `output` defining rendering and output placeholder for custom attrition plot feature.

Details

Similar to .step_attrition the method should return list of `render` and `output` expressions.

See also

Examples

if (interactive()) {
  library(magrittr)
  library(shiny)
  library(cohortBuilder)
  library(shinyCohortBuilder)

  .custom_attrition.tblist <- function(source, id, cohort, session, ...) {
    ns <- session$ns
    choices <- names(source$dtconn)

    list(
      render = shiny::renderPlot({
        cohort$show_attrition(dataset = session$input$attrition_input)
      }),
      output = shiny::tagList(
        shiny::h3("Step-wise Attrition Plot"),
        shiny::selectInput(ns("attrition_input"), "Choose dataset", choices),
        shiny::plotOutput(id)
      )
    )
  }
  coh <- cohort(
    set_source(as.tblist(librarian)),
    step(
      filter(
        "range", id = "copies", dataset = "books",
        variable = "copies", range = c(5, 12)
      )
    ),
    step(
      filter(
        "range", id = "copies", dataset = "books",
        variable = "copies", range = c(6, 8)
      )
    )
  ) %>% run()

  ui <- fluidPage(
    div(id = "attrition")
  )

  server <- function(input, output, session) {
    rendering <- .custom_attrition(
      coh$get_source(), id = "attr", cohort = coh, session = session, dataset = "books"
    )
    insertUI("#attrition", ui = rendering$output)
    output$attr <- rendering$render
  }

  shinyApp(ui, server)
}