Skip to content

Commit

Permalink
extend example_module so it handles decorations
Browse files Browse the repository at this point in the history
  • Loading branch information
m7pr committed Nov 13, 2024
1 parent 6729e4d commit ecbf96f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
41 changes: 29 additions & 12 deletions R/dummy_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
#' shinyApp(app$ui, app$server)
#' }
#' @export
example_module <- function(label = "example teal module", datanames = "all", transforms = list()) {
example_module <- function(label = "example teal module", datanames = "all", transforms = list(),
decorators = teal_transform_module()) {
checkmate::assert_string(label)
ans <- module(
label,
server = function(id, data) {
server = function(id, data, decorators) {
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
datanames_rv <- reactive(names(req(data())))
Expand All @@ -36,28 +37,44 @@ example_module <- function(label = "example teal module", datanames = "all", tra
)
})

table_data <- reactive({
within(data(),
{
table <- dataname
},
dataname = as.name(input$dataname)
)
})

table_data_decorated <- srv_transform_data("decorate", data = table_data, transforms = decorators)

output$text <- renderPrint({
req(input$dataname)
data()[[input$dataname]]
req(table_data_decorated)
table_data_decorated()[['table']]

Check warning on line 53 in R/dummy_functions.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/dummy_functions.R,line=53,col=35,[quotes_linter] Only use double-quotes.
})

teal.widgets::verbatim_popup_srv(
id = "rcode",
verbatim_content = reactive(teal.code::get_code(data())),
verbatim_content = reactive(teal.code::get_code(req(table_data_decorated()))),
title = "Example Code"
)
})
},
ui = function(id) {
ui = function(id, decorators) {
ns <- NS(id)
teal.widgets::standard_layout(
output = verbatimTextOutput(ns("text")),
encoding = tags$div(
selectInput(ns("dataname"), "Choose a dataset", choices = NULL),
teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
)
div(
teal.widgets::standard_layout(
output = verbatimTextOutput(ns("text")),
encoding = tags$div(
selectInput(ns("dataname"), "Choose a dataset", choices = NULL),
teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
)
),
ui_transform_data(ns("decorate"), transforms = decorators)
)
},
ui_args = list(decorators = decorators),
server_args = list(decorators = decorators),
datanames = datanames,
transforms = transforms
)
Expand Down
10 changes: 9 additions & 1 deletion R/teal_transform_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,17 @@
#' )
#' )
#'
#' output_decorator <- teal_transform_module(
#' server = make_teal_transform_server(
#' expression(
#' table <- rev(table)
#' )
#' )
#' )
#'
#' app <- init(
#' data = teal_data(iris = iris),
#' modules = example_module(transforms = data_transforms)
#' modules = example_module(transforms = data_transforms, decorators = output_decorator)
#' )
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
Expand Down

0 comments on commit ecbf96f

Please sign in to comment.