Create the Server and UI Function For the Shiny App
init.Rd
End-users: This is the most important function for you to start a teal app that is composed out of teal modules.
Notes for developers:
This is a wrapper function around the module_teal.R
functions. Unless you are
an end-user, don't use this function, but instead this module.
Arguments
- data
(
TealData
orTealDataset
orTealDatasetConnector
orlist
ordata.frame
orMultiAssayExperiment
)R6
object as returned byteal.data::cdisc_data()
,teal.data::teal_data()
,teal.data::cdisc_dataset()
,teal.data::dataset()
,teal.data::dataset_connector()
orteal.data::cdisc_dataset_connector()
or a singledata.frame
or aMultiAssayExperiment
or a list of the previous objects or function returning a named list. NOTE: teal does not guarantee reproducibility of the code when names of the list elements do not match the original object names. To ensure reproducibility please useteal.data::teal_data()
orteal.data::cdisc_data()
withcheck = TRUE
enabled.- modules
(
list
,teal_modules
orteal_module
)
nested list ofteal_modules
orteal_module
objects or a singleteal_modules
orteal_module
object. These are the specific output modules which will be displayed in the teal application. Seemodules()
andmodule()
for more details.- title
(
NULL
orcharacter
)
The browser window title (defaults to the host URL of the page).- filter
-
(
list
)
You can define filters that show when the app starts. List names should be named according to datanames passed to thedata
argument. In case of data.frame` the list should be composed as follows:list(<dataname1> = list(<varname1> = ..., <varname2> = ...), <dataname2> = list(...), ...)
For example, filters for variable
Sepal.Length
iniris
can be specified as follows:list(iris = list(Sepal.Length = list(selected = c(5.0, 7.0)))) # or list(iris = list(Sepal.Length = c(5.0, 7.0)))
In case developer would like to include
NA
andInf
values in the filtered dataset.list(Species = list(selected = c(5.0, 7.0), keep_na = TRUE, keep_inf = TRUE)) list(Species = c(c(5.0, 7.0), NA, Inf))
To initialize with specific variable filter with all values on start, one can use
list(Species = list())
filter
should be set with respect to the class of the column:numeric
:selected
should be a two elements vector defining the range of the filter.Date
:selected
should be a two elements vector defining the date-range of the filterPOSIXct
:selected
should be a two elements vector defining thedatetime
range of the filtercharacter
andfactor
:selected
should be a vector of any length defining initial values selected to filter.filter
forMultiAssayExperiment
objects should be specified in slightly different way. Since it contains patient data with list of experiments,filter
list should be created as follows:
list( <MAE dataname> = list( subjects = list(<column in colData> = ..., <column in colData> = ...), <experiment name> = list( subset = list(<column in rowData of experiment> = ..., <column in rowData of experiment> = ...), select = list(<column in colData of experiment> = ..., <column in colData of experiment> = ...) ) ) )
By adding the
filterable
attribute it is possible to control which variables can be filtered for each dataset. See the example below whereADSL
can only be filtered byAGE
,SEX
orRACE
. - header
(
shiny.tag
orcharacter
)
the header of the app. Note shiny code placed here (and in the footer argument) will be placed in the app'sui
function so code which needs to be placed in theui
function (such as loading css viahtmltools::htmlDependency()
) should be included here.- footer
(
shiny.tag
orcharacter
)
the footer of the app- id
(
character
)
module id to embed it, if provided, the server function must be called withshiny::moduleServer()
; See the vignette for an example. However,ui_teal_with_splash()
is then preferred to this function.
Examples
library(scda)
ADSL <- synthetic_cdisc_data("latest")$adsl
app <- init(
data = cdisc_data(
cdisc_dataset("ADSL", ADSL),
code = "ADSL <- synthetic_cdisc_data(\"latest\")$adsl"
),
modules = modules(
module(
"data source",
server = function(input, output, session, data) {},
ui = function(id, ...) div(p("information about data source")),
filters = "all"
),
example_module(),
module(
"ADSL AGE histogram",
server = function(input, output, session, data) {
output$hist <- renderPlot(
hist(data[["ADSL"]]()$AGE)
)
},
ui = function(id, ...) {
ns <- NS(id)
plotOutput(ns("hist"))
},
filters = "ADSL"
)
),
title = "App title",
filter = list(ADSL = structure(list(AGE = list()), filterable = c("AGE", "SEX", "RACE"))),
header = tags$h1("Sample App"),
footer = tags$p("Copyright 2017 - 2020")
)
if (interactive()) {
shinyApp(app$ui, app$server)
}