Skip to content

Commit

Permalink
remove DT from vignette/dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
m7pr committed Nov 18, 2024
1 parent 17afb2b commit 72e33f4
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 130 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ Imports:
utils
Suggests:
bslib,
DT (>= 0.33),
knitr (>= 1.42),
mirai (>= 1.1.1),
MultiAssayExperiment,
Expand All @@ -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
Expand Down
128 changes: 0 additions & 128 deletions vignettes/decorate-module-output.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 72e33f4

Please sign in to comment.