insightsengineering / teal

Exploratory Web Apps for Analyzing Clinical Trial Data
https://insightsengineering.github.io/teal/
Other
167 stars 32 forks source link

669 insert UI@main #1253

Open gogonzo opened 1 week ago

gogonzo commented 1 week ago

Fixes #669 #860

to check:

ddl app ```r options( teal.log_level = "TRACE", teal.show_js_log = TRUE, # teal.bs_theme = bslib::bs_theme(version = 5), shiny.bookmarkStore = "server" ) library(scda) pkgload::load_all("teal") # pkgload::load_all("teal.slice") data <- teal_data_module( ui = function(id) { ns <- NS(id) tagList( textInput(ns("username"), label = "Username"), passwordInput(ns("password"), label = "Password"), actionButton(ns("submit"), label = "Submit") ) }, server = function(id, ...) { moduleServer(id, function(input, output, session) { eventReactive(input$submit, { data <- teal_data() |> within( { logger::log_trace("Loading data") ADSL <- scda::synthetic_cdisc_data("latest")$adsl ADTTE <- scda::synthetic_cdisc_data("latest")$adtte iris <- iris }, username = input$username, password = input$password ) join_keys(data) <- default_cdisc_join_keys[c("ADSL", "ADTTE")] data }) }) } ) app <- teal::init( data = data, modules = modules( teal.modules.general::tm_data_table("Data Table"), example_module("Example Module", datanames = "ADTTE"), module( ui = function(id) { ns <- NS(id) tagList( tableOutput(ns("filter_summary")) ) }, server = function(id, datasets) { moduleServer(id, function(input, output, session) { output$filter_summary <- renderTable({ datasets$get_filter_overview(datanames = datasets$datanames()) }) }) } ) ), filter = teal_slices( teal_slice("ADSL", "SEX"), teal_slice("ADSL", "AGE", selected = c(18L, 65L)), module_specific = TRUE, mapping = list( global_filters = "ADSL AGE", `Example Module` = "ADSL SEX" ) ) ) shinyApp(app$ui, app$server) ```
teal as a module ```r options( teal.log_level = "TRACE", teal.show_js_log = TRUE, # teal.bs_theme = bslib::bs_theme(version = 5), shiny.bookmarkStore = "server" ) library(scda) pkgload::load_all("teal") # pkgload::load_all("teal.slice") ui_data <- function(id) { ns <- NS(id) tagList( textInput(ns("username"), label = "Username"), passwordInput(ns("password"), label = "Password"), actionButton(ns("submit"), label = "Submit") ) } srv_data <- function(id, ...) { moduleServer(id, function(input, output, session) { eventReactive(input$submit, { data <- teal_data() |> within( { logger::log_trace("Loading data") ADSL <- scda::synthetic_cdisc_data("latest")$adsl ADTTE <- scda::synthetic_cdisc_data("latest")$adtte iris <- iris }, username = input$username, password = input$password ) join_keys(data) <- default_cdisc_join_keys[c("ADSL", "ADTTE")] data }) }) } modules <- modules( teal.modules.general::tm_data_table("Data Table"), example_module("Example Module", datanames = "ADTTE"), module( ui = function(id) { ns <- NS(id) tagList( tableOutput(ns("filter_summary")) ) }, server = function(id, datasets) { moduleServer(id, function(input, output, session) { output$filter_summary <- renderTable({ datasets$get_filter_overview(datanames = datasets$datanames()) }) }) } ) ) filter <- teal_slices( teal_slice("ADSL", "SEX"), teal_slice("ADSL", "AGE", selected = c(18L, 65L)), module_specific = TRUE, mapping = list( global_filters = "ADSL AGE", `Example Module` = "ADSL SEX" ) ) shinyApp( ui = function(request) { fluidPage( ui_data("data"), ui_teal_1.0(id = "teal", modules = modules) ) }, server = function(input, output, session) { data_rv <- srv_data("data", data = data, modules = modules, filter = filter) srv_teal_1.0(id = "teal", data = data_rv, modules = modules, filter = filter) } ) ```
github-actions[bot] commented 1 week ago

CLA Assistant Lite bot ✅ All contributors have signed the CLA

donyunardi commented 5 days ago

Can app developer provide simple js code to hide all elements of certain class (for example reporter buttons)

So to inject the JS to teal, one will have to code teal as a module so they can pass tags$head(tags$script()) in fluidPage?

donyunardi commented 4 days ago

From the code example:

    data_rv <- srv_data("data", data = data, modules = modules, filter = filter)
    srv_teal_1.0(id = "teal", data = data_rv, modules = modules, filter = filter)

Why do we need to pass built data_rv before passing to srv_teal_1.0?

gogonzo commented 4 days ago

Why do we need to pass built data_rv before passing to srv_teal_1.0?

This is an example of using teal as a module. In this example I prove that you can wrap teal in the external app and pass reactive data to teal, resubmit and it will still work