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(scda)
adsl <- scda_cdisc_dataset_connector(dataname = "ADSL", "adsl")
adlb <- scda_cdisc_dataset_connector(dataname = "ADLB", "adlb")

open_fun <- callable_function(library)
open_fun$set_args(list(package = "scda"))

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(adsl, adlb))

x$set_ui(
  function(id, connection, connectors) {
    ns <- NS(id)
    tagList(
      connection$get_open_ui(ns("open_connection")),
      textInput(ns("name"), p("Choose", code("scda data version")), value = "latest"),
      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(name = input$name))
            # pull each dataset
            connector$get_server()(id = connector$get_dataname())
            if (connector$is_failed()) {
              break
            }
          }
        }
      }
    )
  }
)
if (FALSE) {
x$launch()
x$get_datasets()
}