-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🗃️ decorators
feature branch
#795
Open
m7pr
wants to merge
46
commits into
main
Choose a base branch
from
1187_decorate_output@main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+1,067
−599
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m7pr
commented
Nov 18, 2024
15 tasks
averissimo
reviewed
Nov 18, 2024
averissimo
reviewed
Nov 18, 2024
m7pr
commented
Nov 18, 2024
Signed-off-by: Marcin <[email protected]>
m7pr
commented
Nov 18, 2024
m7pr
commented
Nov 18, 2024
m7pr
commented
Nov 18, 2024
Signed-off-by: Marcin <[email protected]>
m7pr
commented
Nov 19, 2024
Marking this ready for the review, so we can start CI/CD tests |
m7pr
changed the title
Introduce decorators for
introduce decorators for Nov 20, 2024
tm_a_regression
and tm_outliers
tm_a_regression
I moved |
…ou see error from original teal_data
Part of insightsengineering/teal#1370 <details><summary> Working Example </summary> ```r devtools::load_all("../teal") devtools::load_all(".") library(ggplot2) interactive_decorator <- teal_transform_module( ui = function(id) { ns <- NS(id) div( textInput(ns("x_axis_title"), "X axis title", value = "x axis") ) }, server = function(id, data) { moduleServer(id, function(input, output, session) { reactive({ req(data()) within(data(), { plot <- plot + xlab(my_title) }, my_title = input$x_axis_title ) }) }) } ) # general data example data <- teal_data() data <- within(data, { require(nestcolor) CO2 <- data.frame(CO2) }) app <- init( data = data, modules = tm_g_bivariate( x = data_extract_spec( dataname = "CO2", select = select_spec( label = "Select variable:", choices = variable_choices(data[["CO2"]]), selected = "conc", fixed = FALSE ) ), y = data_extract_spec( dataname = "CO2", select = select_spec( label = "Select variable:", choices = variable_choices(data[["CO2"]]), selected = "uptake", multiple = FALSE, fixed = FALSE ) ), row_facet = data_extract_spec( dataname = "CO2", select = select_spec( label = "Select variable:", choices = variable_choices(data[["CO2"]]), selected = "Type", fixed = FALSE ) ), col_facet = data_extract_spec( dataname = "CO2", select = select_spec( label = "Select variable:", choices = variable_choices(data[["CO2"]]), selected = "Treatment", fixed = FALSE ) ), decorators = list(interactive_decorator) ) ) if (interactive()) { shinyApp(app$ui, app$server) } ``` </details> --------- Signed-off-by: Marcin <[email protected]> Co-authored-by: André Veríssimo <[email protected]>
Part of insightsengineering/teal#1370 <details><summary> Working Example </summary> ```r pkgload::load_all("../teal") pkgload::load_all("../teal.modules.general") footnote_dec <- teal_transform_module( label = "Footnote", ui = function(id) shiny::textInput(shiny::NS(id, "footnote"), "Footnote", value = "I am a good decorator"), server = function(id, data) { moduleServer(id, function(input, output, session) { logger::log_info("🟢 Footnote called to action!", namespace = "teal.modules.general") reactive( within( data(), { footnote_str <- footnote plot <- plot + ggplot2::labs(caption = footnote_str) }, footnote = input$footnote ) ) }) } ) title_plot <- teal_transform_module( server = make_teal_transform_server( expression( logger::log_info("🔴 Title being called to action!", namespace = "teal.modules.general"), plot <- plot + ggplot2::ggtitle("A title to the plot") ) ) ) # CDISC data example data <- teal_data() data <- within(data, { require(nestcolor) ADSL <- rADSL }) join_keys(data) <- default_cdisc_join_keys[names(data)] app <- init( data = data, modules = modules( tm_g_response( label = "Response Plots", decorators = list(footnote_dec, title_plot), response = data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variable:", choices = variable_choices(data[["ADSL"]], c("BMRKR2", "COUNTRY")), selected = "BMRKR2", multiple = FALSE, fixed = FALSE ) ), x = data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variable:", choices = variable_choices(data[["ADSL"]], c("SEX", "RACE")), selected = "RACE", multiple = FALSE, fixed = FALSE ) ) ) ) ) if (interactive()) { shinyApp(app$ui, app$server) } ``` </details> --------- Signed-off-by: André Veríssimo <[email protected]>
Part of insightsengineering/teal#1370 <details><summary> Working Example </summary> ```r pkgload::load_all("../teal") pkgload::load_all("../teal.modules.general") footnote_dec <- teal_transform_module( label = "Footnote", ui = function(id) shiny::textInput(shiny::NS(id, "footnote"), "Footnote", value = "I am a good decorator"), server = function(id, data) { moduleServer(id, function(input, output, session) { logger::log_info("🟢 Footnote called to action!", namespace = "teal.modules.general") reactive( within( data(), { footnote_str <- footnote plot <- plot + ggplot2::labs(caption = footnote_str) }, footnote = input$footnote ) ) }) } ) table_dup_dec <- teal_transform_module( server = make_teal_transform_server( expression( logger::log_info("🔴 Table dup being called to action!", namespace = "teal.modules.general"), summary_table <- rbind(summary_table, summary_table), if (exists("test_table")) test_table <- rbind(test_table, test_table, test_table) ) ) ) # CDISC data example data <- teal_data() data <- within(data, { ADSL <- rADSL }) join_keys(data) <- default_cdisc_join_keys[names(data)] vars1 <- choices_selected( variable_choices(data[["ADSL"]], c("ARM", "COUNTRY", "SEX")), selected = NULL ) app <- init( data = data, modules = modules( tm_g_distribution( decorators = list(footnote_dec, table_dup_dec), dist_var = data_extract_spec( dataname = "ADSL", select = select_spec( choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE ) ), strata_var = data_extract_spec( dataname = "ADSL", filter = filter_spec( vars = vars1, multiple = TRUE ) ), group_var = data_extract_spec( dataname = "ADSL", filter = filter_spec( vars = vars1, multiple = TRUE ) ) ) ) ) if (interactive()) { shinyApp(app$ui, app$server) } ``` </details> --------- Signed-off-by: André Veríssimo <[email protected]>
averissimo
reviewed
Nov 22, 2024
averissimo
reviewed
Nov 22, 2024
averissimo
changed the title
introduce decorators for
Feature branch: introduce decorators for Nov 22, 2024
tm_a_regression
tm_a_regression
averissimo
reviewed
Nov 22, 2024
R/tm_g_distribution.R
Outdated
g <- plot_call | ||
print(g) | ||
plot <- plot_call | ||
print(plot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to move this later on
Part of insightsengineering/teal#1370 <details><summary> Working Example </summary> ````r devtools::load_all("../teal") devtools::load_all(".") split_by_decorator <- teal_transform_module( label = "Footnote", ui = function(id) shiny::textInput( shiny::NS(id, "text"), "Insert row", "Hello World!" ), server = function(id, data) { moduleServer(id, function(input, output, session) { logger::log_info("🟢 Text called to action!", namespace = "teal.modules.general") reactive( within( data(), { table <- table %>% insert_rrow(rrow(text)) }, text = input$text ) ) }) } ) # CDISC data example data <- teal_data() data <- within(data, { ADSL <- rADSL }) join_keys(data) <- default_cdisc_join_keys[names(data)] app <- init( data = data, modules = modules( tm_t_crosstable( label = "Cross Table", x = data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variable:", choices = variable_choices(data[["ADSL"]], subset = function(data) { idx <- !vapply(data, inherits, logical(1), c("Date", "POSIXct", "POSIXlt")) return(names(data)[idx]) }), selected = "COUNTRY", multiple = TRUE, ordered = TRUE, fixed = FALSE ) ), y = data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variable:", choices = variable_choices(data[["ADSL"]], subset = function(data) { idx <- vapply(data, is.factor, logical(1)) return(names(data)[idx]) }), selected = "SEX", multiple = FALSE, fixed = FALSE ) ), decorators = list(split_by_decorator) ) ) ) if (interactive()) { shinyApp(app$ui, app$server) } ```` </details> --------- Signed-off-by: Marcin <[email protected]> Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: André Veríssimo <[email protected]>
Part of insightsengineering/teal#1370 <details><summary> Working Example </summary> ```r devtools::load_all("../teal") devtools::load_all(".") plot_title <- teal_transform_module( server = make_teal_transform_server(expression({ plot <- plot + ggtitle("Custom title") })) ) # general data example data <- teal_data() data <- within(data, { require(nestcolor) USArrests <- USArrests }) app <- init( data = data, modules = modules( tm_a_pca( "PCA", dat = data_extract_spec( dataname = "USArrests", select = select_spec( choices = variable_choices( data = data[["USArrests"]], c("Murder", "Assault", "UrbanPop", "Rape") ), selected = c("Murder", "Assault"), multiple = TRUE ), filter = NULL ), decorators = list(plot_title) ) ) ) if (interactive()) { shinyApp(app$ui, app$server) } ``` </details> --------- Signed-off-by: Marcin <[email protected]> Co-authored-by: André Veríssimo <[email protected]>
averissimo
changed the title
Feature branch: introduce decorators for
🗃️ Nov 22, 2024
tm_a_regression
decorators
feature branch
Signed-off-by: André Veríssimo <[email protected]> Co-authored-by: André Veríssimo <[email protected]>
Part of insightsengineering/teal#1370 <details><summary> Working Example </summary> ```r pkgload::load_all("../teal") pkgload::load_all(".") footnote_dec <- teal_transform_module( label = "Footnote", ui = function(id) shiny::textInput(shiny::NS(id, "footnote"), "Footnote", value = "I am a good decorator"), server = function(id, data) { moduleServer(id, function(input, output, session) { logger::log_info("🟢 Footnote called to action!", namespace = "teal.modules.general") reactive( within( data(), { plot$xlab <- footnote }, footnote = input$footnote ) ) }) } ) # general data example data <- teal_data() data <- within(data, { countries <- data.frame( id = c("DE", "FR", "IT", "ES", "PT", "GR", "NL", "BE", "LU", "AT"), government = factor( c(2, 2, 2, 1, 2, 2, 1, 1, 1, 2), labels = c("Monarchy", "Republic") ), language_family = factor( c(1, 3, 3, 3, 3, 2, 1, 1, 3, 1), labels = c("Germanic", "Hellenic", "Romance") ), population = c(83, 67, 60, 47, 10, 11, 17, 11, 0.6, 9), area = c(357, 551, 301, 505, 92, 132, 41, 30, 2.6, 83), gdp = c(3.4, 2.7, 2.1, 1.4, 0.3, 0.2, 0.7, 0.5, 0.1, 0.4), debt = c(2.1, 2.3, 2.4, 2.6, 2.3, 2.4, 2.3, 2.4, 2.3, 2.4) ) sales <- data.frame( id = 1:50, country_id = sample( c("DE", "FR", "IT", "ES", "PT", "GR", "NL", "BE", "LU", "AT"), size = 50, replace = TRUE ), year = sort(sample(2010:2020, 50, replace = TRUE)), venue = sample(c("small", "medium", "large", "online"), 50, replace = TRUE), cancelled = sample(c(TRUE, FALSE), 50, replace = TRUE), quantity = rnorm(50, 100, 20), costs = rnorm(50, 80, 20), profit = rnorm(50, 20, 10) ) }) join_keys(data) <- join_keys( join_key("countries", "countries", "id"), join_key("sales", "sales", "id"), join_key("countries", "sales", c("id" = "country_id")) ) app <- init( data = data, modules = modules( tm_g_scatterplotmatrix( label = "Scatterplot matrix", variables = list( data_extract_spec( dataname = "countries", select = select_spec( label = "Select variables:", choices = variable_choices(data[["countries"]]), selected = c("area", "gdp", "debt"), multiple = TRUE, ordered = TRUE, fixed = FALSE ) ), data_extract_spec( dataname = "sales", filter = filter_spec( label = "Select variable:", vars = "country_id", choices = value_choices(data[["sales"]], "country_id"), selected = c("DE", "FR", "IT", "ES", "PT", "GR", "NL", "BE", "LU", "AT"), multiple = TRUE ), select = select_spec( label = "Select variables:", choices = variable_choices(data[["sales"]], c("quantity", "costs", "profit")), selected = c("quantity", "costs", "profit"), multiple = TRUE, ordered = TRUE, fixed = FALSE ) ) ), decorators = list(footnote_dec) ) ) ) if (interactive()) { shinyApp(app$ui, app$server) } ``` </details> --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: André Veríssimo <[email protected]>
Part of insightsengineering/teal#1370 <details><summary> Working Example </summary> ```r pkgload::load_all("../teal") pkgload::load_all(".") footnote_dec <- teal_transform_module( label = "Footnote", ui = function(id) shiny::textInput(shiny::NS(id, "footnote"), "Footnote", value = "I am a good decorator"), server = function(id, data) { moduleServer(id, function(input, output, session) { logger::log_info("🟢 Footnote called to action!", namespace = "teal.modules.general") reactive( within( data(), { footnote_str <- footnote plot <- plot + ggplot2::labs(caption = footnote_str) }, footnote = input$footnote ) ) }) } ) # CDISC data example data <- teal_data() data <- within(data, { require(nestcolor) ADSL <- rADSL }) join_keys(data) <- default_cdisc_join_keys[names(data)] app <- init( data = data, modules = modules( tm_g_scatterplot( label = "Scatterplot Choices", x = data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variable:", choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2")), selected = "AGE", multiple = FALSE, fixed = FALSE ) ), y = data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variable:", choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE ) ), color_by = data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variable:", choices = variable_choices( data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2", "RACE", "REGION1") ), selected = NULL, multiple = FALSE, fixed = FALSE ) ), size_by = data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variable:", choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), selected = "AGE", multiple = FALSE, fixed = FALSE ) ), row_facet = data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variable:", choices = variable_choices(data[["ADSL"]], c("BMRKR2", "RACE", "REGION1")), selected = NULL, multiple = FALSE, fixed = FALSE ) ), col_facet = data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variable:", choices = variable_choices(data[["ADSL"]], c("BMRKR2", "RACE", "REGION1")), selected = NULL, multiple = FALSE, fixed = FALSE ) ), decorators = list(footnote_dec) ) ) ) if (interactive()) { shinyApp(app$ui, app$server) } ``` </details> --------- Signed-off-by: Marcin <[email protected]> Co-authored-by: André Veríssimo <[email protected]>
Part of insightsengineering/teal#1370 <details><summary> Working Example </summary> ```r devtools::load_all("../teal") devtools::load_all(".") interactive_decorator <- teal_transform_module( ui = function(id) { ns <- NS(id) div( textInput(ns("x_axis_title_top"), "X axis title plot top", value = "x axis top"), textInput(ns("x_axis_title_bottom"), "X axis title plot bottom", value = "x axis bottom") ) }, server = function(id, data) { moduleServer(id, function(input, output, session) { reactive({ req(data()) within(data(), { plot_bottom <- plot_bottom + xlab(my_title_bottom) plot_top <- plot_top + xlab(my_title_top) }, my_title_top = input$x_axis_title_top, my_title_bottom = input$x_axis_title_bottom ) }) }) } ) # general data example data <- teal_data() data <- within(data, { require(nestcolor) CO2 <- CO2 factors <- names(Filter(isTRUE, vapply(CO2, is.factor, logical(1L)))) CO2[factors] <- lapply(CO2[factors], as.character) }) app <- init( data = data, modules = modules( tm_g_association( ref = data_extract_spec( dataname = "CO2", select = select_spec( label = "Select variable:", choices = variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")), selected = "Plant", fixed = FALSE ) ), vars = data_extract_spec( dataname = "CO2", select = select_spec( label = "Select variables:", choices = variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")), selected = "Treatment", multiple = TRUE, fixed = FALSE ) ), decorators = list(interactive_decorator) ) ) ) if (interactive()) { shinyApp(app$ui, app$server) } ``` </details> --------- Co-authored-by: André Veríssimo <[email protected]>
Part of insightsengineering/teal#1370 <details><summary> Working Example </summary> ```r devtools::load_all("../teal") devtools::load_all(".") # general data example data <- teal_data() data <- within(data, { require(nestcolor) iris <- iris }) custom_table_decorator_interactive <- 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(), input$style) within(data(), { if (style == "Striped") { table <- DT::formatStyle( table, columns = attr(table$x, "colnames")[-1], target = 'row', backgroundColor = '#f9f9f9' ) } else if (style == "Hover") { table <- DT::formatStyle( table, columns = attr(table$x, "colnames")[-1], target = 'row', backgroundColor = '#f0f0f0' ) } }, style = input$style ) }) }) } ) app <- init( data = data, modules = modules( tm_data_table( variables_selected = list( iris = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species") ), dt_args = list(caption = "IRIS Table Caption"), decorators = list(custom_table_decorator_interactive) ) ) ) if (interactive()) { shinyApp(app$ui, app$server) } ``` </details> --------- Signed-off-by: Marcin <[email protected]> Co-authored-by: André Veríssimo <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Partner to insightsengineering/teal#1357
Introduces decorators to modules. More about decorators in here insightsengineering/teal#1384
Current working example for tm_a_regression