Skip to contents

[Stable] Class manages TealDatasetConnector to specify additional dynamic arguments and to open/close connection.

Super class

teal.data::TealDataAbstract -> TealDataConnector

Methods

Inherited methods


Method new()

Create a new TealDataConnector object

Usage

TealDataConnector$new(connection, connectors)

Arguments

connection

(TealDataConnection)
connection to data source

connectors

(list of TealDatasetConnector elements)
list with dataset connectors


Method print()

Prints this TealDataConnector.

Usage

TealDataConnector$print(...)

Arguments

...

additional arguments to the printing method

Returns

invisibly self


Method get_connection()

Get connection to data source

Usage

TealDataConnector$get_connection()

Returns

connector's connection


Method get_code_class()

Get internal CodeClass object

Usage

TealDataConnector$get_code_class()

Returns

CodeClass


Method get_server()

get the server function

Usage

TealDataConnector$get_server()

Returns

the server function


Method get_preopen_server()

get the preopen server function

Usage

TealDataConnector$get_preopen_server()

Returns

the server function


Method get_ui()

Get Shiny module with inputs for all TealDatasetConnector objects

Usage

TealDataConnector$get_ui(id)

Arguments

id

character shiny element id

Returns

the ui function


Method set_pull_args()

Set argument to the pull_fun

Usage

TealDataConnector$set_pull_args(args)

Arguments

args

(named list)
arguments values as separate list elements named by argument name. These arguments are passed to each dataset.

Returns

nothing


Method set_ui()

Set connector UI function

Usage

TealDataConnector$set_ui(f)

Arguments

f

(function)
shiny module as function. Inputs specified in this ui are passed to server module defined by set_server method.

Returns

nothing


Method set_server()

Set connector server function

This function will be called after submit button will be hit. There is no possibility to specify some dynamic ui as server function is executed after hitting submit button.

Usage

TealDataConnector$set_server(f)

Arguments

f

(function)
A shiny module server function that should load data from all connectors

Returns

nothing


Method set_preopen_server()

Set connector pre-open server function

This function will be called before submit button will be hit.

Usage

TealDataConnector$set_preopen_server(f)

Arguments

f

(function)
A shiny module server function

Returns

nothing


Method pull()

Load data from each TealDatasetConnector

Usage

TealDataConnector$pull(con_args = NULL, args = NULL, try = TRUE)

Arguments

con_args

(NULL or named list)
additional dynamic arguments for connection function. args will be passed to each TealDatasetConnector object to evaluate CallableFunction assigned to this dataset. If args is null than default set of arguments will be used, otherwise call will be executed on these arguments only (arguments set before will be ignored). pull function doesn't update reproducible call, it's just evaluate function.

args

(NULL or named list)
additional dynamic arguments to pull dataset. args will be passed to each TealDatasetConnector object to evaluate CallableFunction assigned to this dataset. If args is null than default set of arguments will be used, otherwise call will be executed on these arguments only (arguments set before will be ignored). pull function doesn't update reproducible call, it's just evaluate function.

try

(logical value)
whether perform function evaluation inside try clause

Returns

(self) invisibly for chaining. In order to get the data please use get_datasets method.


Method launch()

Run simple application that uses its ui and server fields to pull data from connection.

Useful for debugging

Usage

TealDataConnector$launch()

Returns

An object that represents the app


Method mutate()

Mutate data by code.

Usage

TealDataConnector$mutate(...)

Arguments

...

parameters inherited from TealDataAbstract.

Returns

Informational message to not use mutate_data() with TealDataConnectors.


Method is_failed()

Check if pull or connection has not failed.

Usage

TealDataConnector$is_failed()

Returns

TRUE if pull or connection failed, else FALSE


Method clone()

The objects of this class are cloneable with this method.

Usage

TealDataConnector$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

library(magrittr)
#> 
#> Attaching package: ‘magrittr’
#> The following objects are masked from ‘package:testthat’:
#> 
#>     equals, is_less_than, not

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 <- teal.data:::TealDataConnector$new(
  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()
}