Skip to contents

[Stable]

Usage

relational_data_connector(connection, connectors)

Arguments

connection

(TealDataConnection)
connection to data source

connectors

(list of TealDatasetConnector elements)
list with dataset connectors

Value

TealDataConnector object

Examples

library(magrittr)
random_data_connector <- function(dataname) {
  fun_dataset_connector(
    dataname = dataname,
    fun = teal.data::example_cdisc_data,
    fun_args = list(dataname = dataname),
  )
}

open_fun <- callable_function(library)
open_fun$set_args(list(package = "teal.data"))

con <- data_connection(open_fun = open_fun)
con$set_open_server(
  function(id, connection) {
    moduleServer(
      id = id,
      module = function(input, output, session) {
        connection$open(try = TRUE)
        return(invisible(connection))
      }
    )
  }
)

x <- relational_data_connector(
  connection = con,
  connectors = list(
    random_data_connector(dataname = "ADSL"),
    random_data_connector(dataname = "ADLB")
  )
)

x$set_ui(
  function(id, connection, connectors) {
    ns <- NS(id)
    tagList(
      connection$get_open_ui(ns("open_connection")),
      numericInput(inputId = ns("n"), label = "Choose number of records", min = 0, value = 1),
      do.call(
        what = "tagList",
        args = lapply(
          connectors,
          function(connector) {
            div(
              connector$get_ui(
                id = ns(connector$get_dataname())
              ),
              br()
            )
          }
        )
      )
    )
  }
)

x$set_server(
  function(id, connection, connectors) {
    moduleServer(
      id = id,
      module = function(input, output, session) {
        # opens connection
        connection$get_open_server()(id = "open_connection", connection = connection)
        if (connection$is_opened()) {
          for (connector in connectors) {
            set_args(connector, args = list(n = input$n))
            # pull each dataset
            connector$get_server()(id = connector$get_dataname())
            if (connector$is_failed()) {
              break
            }
          }
        }
      }
    )
  }
)
if (FALSE) {
x$launch()
x$get_datasets()
}