diff --git a/DESCRIPTION b/DESCRIPTION index b0440f0211..cd054ecb10 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -57,7 +57,6 @@ Imports: utils Suggests: bslib, - DT (>= 0.33), knitr (>= 1.42), mirai (>= 1.1.1), MultiAssayExperiment, @@ -83,7 +82,7 @@ Config/Needs/verdepcheck: rstudio/shiny, insightsengineering/teal.data, insightsengineering/teal.reporter, insightsengineering/teal.widgets, rstudio/bslib, yihui/knitr, bioc::MultiAssayExperiment, r-lib/R6, rstudio/rmarkdown, tidyverse/rvest, rstudio/shinytest2, - rstudio/shinyvalidate, r-lib/testthat, r-lib/withr, rstudio/DT, + rstudio/shinyvalidate, r-lib/testthat, r-lib/withr, yaml=vubiostat/r-yaml Config/Needs/website: insightsengineering/nesttemplate Encoding: UTF-8 diff --git a/vignettes/decorate-module-output.Rmd b/vignettes/decorate-module-output.Rmd index 1bbb4dc721..670e3cd849 100644 --- a/vignettes/decorate-module-output.Rmd +++ b/vignettes/decorate-module-output.Rmd @@ -265,134 +265,6 @@ if (interactive()) { } ``` -## Decorating Tables - -### Example Module - -The next example contains a decorator that formats the background style of `DT::datable`, depending on the selected `Table Style` (`style`) input. - - -```{r, eval=requireNamespace("DT")} -library(DT) - -# Define a decorator module for customizing table appearance -custom_table_decorator <- teal_transform_module( - ui = function(id) { - ns <- NS(id) - div( - selectInput( - ns("style"), - "Table Style", - choices = c("Default", "Striped", "Hover"), - selected = "Default" - ) - ) - }, - server = function(id, data) { - moduleServer(id, function(input, output, session) { - reactive({ - req(data()) - within(data(), - { - if (style == "Striped") { - table <- - formatStyle( - table, - columns = attr(table$x, "colnames")[-1], - target = "row", - backgroundColor = "#f9f9f9" - ) - } else if (style == "Hover") { - table <- - formatStyle( - table, - columns = attr(table$x, "colnames")[-1], - target = "row", - backgroundColor = "#f0f0f0" - ) - } - }, - style = input$style - ) - }) - }) - } -) -``` - - - -```{r, eval=requireNamespace("DT")} -# Main module to display the table with the decorator applied -tm_custom_table <- function(label = "Customized Table Module", decorators = teal_transform_module()) { - module( - label = label, - ui = function(id, decorators) { - ns <- NS(id) - div( - selectInput(ns("dataset"), "Select Dataset", choices = NULL), - ui_teal_transform_data(ns("decorate"), transformators = decorators), - DT::dataTableOutput(ns("table_output")), - verbatimTextOutput(ns("code_output")) - ) - }, - server = function(id, data, decorators) { - moduleServer(id, function(input, output, session) { - observeEvent(data(), { - updateSelectInput(inputId = "dataset", choices = names(data())) - }) - - base_table <- reactive({ - req(input$dataset) - within(data(), - { - table <- - DT::datatable( - dataset, - options = list( - dom = "t", - autoWidth = TRUE - ) - ) - }, - dataset = as.name(input$dataset) - ) - }) - - decorated_table <- - srv_teal_transform_data("decorate", data = base_table, transformators = decorators) - - output$table_output <- DT::renderDT({ - req(decorated_table()) - decorated_table()[["table"]] - }) - - output$code_output <- renderText({ - teal.code::get_code(req(decorated_table())) - }) - }) - }, - ui_args = list(decorators = decorators), - server_args = list(decorators = decorators) - ) -} -``` - -### Application - -```{r, eval=requireNamespace("DT")} -app <- init( - data = teal_data(mtcars = mtcars, iris = iris), - modules = modules( - tm_custom_table("custom_table", decorators = custom_table_decorator) - ) -) - -if (interactive()) { - shinyApp(app$ui, app$server) -} -``` - ## Multiple Decorators ### Example Module