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.
Usage
init(
data,
modules,
title = NULL,
filter = teal_slices(),
header = tags$p(),
footer = tags$p(),
id = character(0)
)
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
(
teal_slices
)
Specification of initial filter. Filters can be specified usingteal_slices()
. Old way of specifying filters through a list is deprecated and will be removed in the next release. Please fix your applications to useteal_slices()
.- 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 loadingCSS
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
new_iris <- transform(iris, id = seq_len(nrow(iris)))
new_mtcars <- transform(mtcars, id = seq_len(nrow(mtcars)))
app <- init(
data = teal_data(
dataset("new_iris", new_iris),
dataset("new_mtcars", new_mtcars),
code = "
new_iris <- transform(iris, id = seq_len(nrow(iris)))
new_mtcars <- transform(mtcars, id = seq_len(nrow(mtcars)))
"
),
modules = modules(
module(
label = "data source",
server = function(input, output, session, data) {},
ui = function(id, ...) div(p("information about data source")),
datanames = "all"
),
example_module(label = "example teal module"),
module(
"Iris Sepal.Length histogram",
server = function(input, output, session, data) {
output$hist <- renderPlot(
hist(data[["new_iris"]]()$Sepal.Length)
)
},
ui = function(id, ...) {
ns <- NS(id)
plotOutput(ns("hist"))
},
datanames = "new_iris"
)
),
title = "App title",
filter = teal_slices(
teal_slice(dataname = "new_iris", varname = "Species"),
teal_slice(dataname = "new_iris", varname = "Sepal.Length"),
teal_slice(dataname = "new_mtcars", varname = "cyl"),
exclude_varnames = list(new_iris = c("Sepal.Width", "Petal.Width")),
mapping = list(
`example teal module` = "new_iris Species",
`Iris Sepal.Length histogram` = "new_iris Species",
global_filters = "new_mtcars cyl"
)
),
header = tags$h1("Sample App"),
footer = tags$p("Copyright 2017 - 2023")
)
if (interactive()) {
shinyApp(app$ui, app$server)
}