From bc9a895d3bf3ab30032db298688c3a6f8f02eb7f Mon Sep 17 00:00:00 2001 From: Andreas Gammelgaard Damsbo Date: Tue, 13 May 2025 08:48:45 +0200 Subject: [PATCH] prepare for reactive theming - only setting theme on render --- R/regression-module.R | 49 ++++++++++++++++++++++++----------- R/regression_table.R | 2 +- inst/apps/FreesearchR/app.R | 51 +++++++++++++++++++++++++------------ 3 files changed, 70 insertions(+), 32 deletions(-) diff --git a/R/regression-module.R b/R/regression-module.R index 4d7f656..f79c0c5 100644 --- a/R/regression-module.R +++ b/R/regression-module.R @@ -65,16 +65,6 @@ regression_ui <- function(id, ...) { # ) # ), shiny::uiOutput(outputId = ns("regression_type")), - shiny::radioButtons( - inputId = ns("add_regression_p"), - label = "Add p-value", - inline = TRUE, - selected = "yes", - choices = list( - "Yes" = "yes", - "No" = "no" - ) - ), shiny::radioButtons( inputId = ns("all"), label = "Specify covariables", @@ -105,6 +95,29 @@ regression_ui <- function(id, ...) { auto_reset = TRUE ), shiny::helpText("Press 'Analyse' to create the regression model and after changing parameters."), + shiny::tags$br(), + shiny::radioButtons( + inputId = ns("add_regression_p"), + label = "Show p-value", + inline = TRUE, + selected = "yes", + choices = list( + "Yes" = "yes", + "No" = "no" + ) + ), + # shiny::tags$br(), + # shiny::radioButtons( + # inputId = ns("tbl_theme"), + # label = "Show p-value", + # inline = TRUE, + # selected = "jama", + # choices = list( + # "JAMA" = "jama", + # "Lancet" = "lancet", + # "NEJM" = "nejm" + # ) + # ), shiny::tags$br() ), do.call( @@ -510,7 +523,6 @@ regression_server <- function(id, rv$list$regression$tables <- out rv$list$input <- input - }, warning = function(warn) { showNotification(paste0(warn), type = "warning") @@ -522,21 +534,28 @@ regression_server <- function(id, } ) + ## Consider creating merged table with theming and then passing object + ## to render. output$table2 <- gt::render_gt({ ## Print checks if a regression table is present if (!is.null(rv$list$regression$tables)) { - out <- rv$list$regression$tables |> + gtsummary::theme_gtsummary_journal(journal = "jama") + merged <- rv$list$regression$tables |> tbl_merge() if (input$add_regression_p == "no") { - out <- out |> + merged <- merged |> gtsummary::modify_column_hide(column = dplyr::starts_with("p.value")) } - out |> + out <- merged |> gtsummary::as_gt() |> gt::tab_header(gt::md(glue::glue("**Table 2: {rv$list$regression$params$descr}**"))) + + rv$list$regression$table_merged + + out } else { return(NULL) } @@ -630,7 +649,7 @@ regression_server <- function(id, ############################################################################## return(shiny::reactive({ - rv$list + rv$list })) } ) diff --git a/R/regression_table.R b/R/regression_table.R index 557359b..b0331c7 100644 --- a/R/regression_table.R +++ b/R/regression_table.R @@ -140,7 +140,7 @@ regression_table_create <- function(x, ..., args.list = NULL, fun = "gtsummary:: } } - gtsummary::theme_gtsummary_journal(journal = theme) + # gtsummary::theme_gtsummary_journal(journal = theme) if (inherits(x, "polr")) { # browser() out <- do.call(getfun(fun), c(list(x = x), args.list)) diff --git a/inst/apps/FreesearchR/app.R b/inst/apps/FreesearchR/app.R index a018072..646d441 100644 --- a/inst/apps/FreesearchR/app.R +++ b/inst/apps/FreesearchR/app.R @@ -7134,7 +7134,7 @@ regression_table_create <- function(x, ..., args.list = NULL, fun = "gtsummary:: } } - gtsummary::theme_gtsummary_journal(journal = theme) + # gtsummary::theme_gtsummary_journal(journal = theme) if (inherits(x, "polr")) { # browser() out <- do.call(getfun(fun), c(list(x = x), args.list)) @@ -7248,16 +7248,6 @@ regression_ui <- function(id, ...) { # ) # ), shiny::uiOutput(outputId = ns("regression_type")), - shiny::radioButtons( - inputId = ns("add_regression_p"), - label = "Add p-value", - inline = TRUE, - selected = "yes", - choices = list( - "Yes" = "yes", - "No" = "no" - ) - ), shiny::radioButtons( inputId = ns("all"), label = "Specify covariables", @@ -7288,6 +7278,29 @@ regression_ui <- function(id, ...) { auto_reset = TRUE ), shiny::helpText("Press 'Analyse' to create the regression model and after changing parameters."), + shiny::tags$br(), + shiny::radioButtons( + inputId = ns("add_regression_p"), + label = "Show p-value", + inline = TRUE, + selected = "yes", + choices = list( + "Yes" = "yes", + "No" = "no" + ) + ), + # shiny::tags$br(), + # shiny::radioButtons( + # inputId = ns("tbl_theme"), + # label = "Show p-value", + # inline = TRUE, + # selected = "jama", + # choices = list( + # "JAMA" = "jama", + # "Lancet" = "lancet", + # "NEJM" = "nejm" + # ) + # ), shiny::tags$br() ), do.call( @@ -7693,7 +7706,6 @@ regression_server <- function(id, rv$list$regression$tables <- out rv$list$input <- input - }, warning = function(warn) { showNotification(paste0(warn), type = "warning") @@ -7705,21 +7717,28 @@ regression_server <- function(id, } ) + ## Consider creating merged table with theming and then passing object + ## to render. output$table2 <- gt::render_gt({ ## Print checks if a regression table is present if (!is.null(rv$list$regression$tables)) { - out <- rv$list$regression$tables |> + gtsummary::theme_gtsummary_journal(journal = "jama") + merged <- rv$list$regression$tables |> tbl_merge() if (input$add_regression_p == "no") { - out <- out |> + merged <- merged |> gtsummary::modify_column_hide(column = dplyr::starts_with("p.value")) } - out |> + out <- merged |> gtsummary::as_gt() |> gt::tab_header(gt::md(glue::glue("**Table 2: {rv$list$regression$params$descr}**"))) + + rv$list$regression$table_merged + + out } else { return(NULL) } @@ -7813,7 +7832,7 @@ regression_server <- function(id, ############################################################################## return(shiny::reactive({ - rv$list + rv$list })) } )