From e980edc149d184b9e4765c2eaaa5f4eb1ac0eee0 Mon Sep 17 00:00:00 2001 From: Andreas Gammelgaard Damsbo Date: Mon, 14 Apr 2025 11:18:24 +0200 Subject: [PATCH] Code export adjusted --- R/app_version.R | 2 +- R/helpers.R | 4 +-- inst/apps/FreesearchR/app.R | 36 +++++++++++-------- .../shinyapps.io/agdamsbo/freesearcheR.dcf | 2 +- inst/apps/FreesearchR/server.R | 14 +++++--- inst/apps/FreesearchR/ui.R | 16 ++++++--- 6 files changed, 45 insertions(+), 29 deletions(-) diff --git a/R/app_version.R b/R/app_version.R index 16c5faa..6587a1c 100644 --- a/R/app_version.R +++ b/R/app_version.R @@ -1 +1 @@ -app_version <- function()'Version: 25.4.2.250414_1007' +app_version <- function()'Version: 25.4.3.250414_1045' diff --git a/R/helpers.R b/R/helpers.R index 6d2462c..3a5cf37 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -378,9 +378,7 @@ data_type_filter <- function(data,type){ out <- data[data_type(data) %in% type] code <- rlang::call2("data_type_filter",!!!list(type=type),.ns = "FreesearchR") - if (!is.null(code)){ - attr(out, "code") <- code - } + attr(out, "code") <- code out } diff --git a/inst/apps/FreesearchR/app.R b/inst/apps/FreesearchR/app.R index de36f68..8f9beb5 100644 --- a/inst/apps/FreesearchR/app.R +++ b/inst/apps/FreesearchR/app.R @@ -10,7 +10,7 @@ #### Current file: /Users/au301842/FreesearchR/R//app_version.R ######## -app_version <- function()'Version: 25.4.2.250414_1007' +app_version <- function()'Version: 25.4.3.250414_1045' ######## @@ -2737,9 +2737,7 @@ data_type_filter <- function(data,type){ out <- data[data_type(data) %in% type] code <- rlang::call2("data_type_filter",!!!list(type=type),.ns = "FreesearchR") - if (!is.null(code)){ - attr(out, "code") <- code - } + attr(out, "code") <- code out } @@ -8293,8 +8291,12 @@ ui_elements <- list( shiny::tags$br(), shiny::tags$br(), shiny::uiOutput(outputId = "column_filter"), + shiny::helpText("Variable data type filtering."), + shiny::tags$br(), shiny::tags$br(), IDEAFilter::IDEAFilter_ui("data_filter"), + shiny::helpText("Observations level filtering."), + shiny::tags$br(), shiny::tags$br() ) ), @@ -8312,8 +8314,8 @@ ui_elements <- list( width = 9, shiny::tags$p( shiny::markdown("Below, are several options for simple data manipulation like update variables by renaming, creating new labels (for nicer tables in the report) and changing variable classes (numeric, factor/categorical etc.)."), - shiny::tags$p("There are also more advanced options to modify factor/categorical variables as well as create new factor from a continous variable or new variables with *R* code. At the bottom you can restore the original data."), - shiny::tags$p("Please note that data modifications are applied before any data or variable filtering is applied.") + shiny::markdown("There are also more advanced options to modify factor/categorical variables as well as create new factor from a continous variable or new variables with *R* code. At the bottom you can restore the original data."), + shiny::markdown("Please note that data modifications are applied before any data or variable filtering is applied.") ) ) ), @@ -8334,6 +8336,7 @@ ui_elements <- list( ), shiny::tags$br(), shiny::helpText("Reorder the levels of factor/categorical variables."), + shiny::tags$br() ), shiny::column( width = 4, @@ -8343,7 +8346,8 @@ ui_elements <- list( width = "100%" ), shiny::tags$br(), - shiny::helpText("Create factor/categorical variable from a continous variable (number/date/time).") + shiny::helpText("Create factor/categorical variable from a continous variable (number/date/time)."), + shiny::tags$br() ), shiny::column( width = 4, @@ -8353,11 +8357,11 @@ ui_elements <- list( width = "100%" ), shiny::tags$br(), - shiny::helpText(shiny::markdown("Create a new variable/column based on an *R*-expression.")) + shiny::helpText(shiny::markdown("Create a new variable/column based on an *R*-expression.")), + shiny::tags$br() ) ), shiny::tags$br(), - shiny::tags$br(), tags$h4("Compare modified data to original"), shiny::tags$br(), shiny::tags$p( @@ -8949,7 +8953,7 @@ server <- function(input, output, session) { output$data_info <- shiny::renderUI({ shiny::req(data_filter()) - data_description(data_filter(),"The filtered data") + data_description(data_filter(), "The filtered data") }) ######### Create factor @@ -9043,12 +9047,13 @@ server <- function(input, output, session) { }) shiny::observeEvent(list( - input$column_filter#, + input$column_filter # , # rv$data ), { shiny::req(input$column_filter) - rv$data_variables <- data_type_filter(rv$data, input$column_filter) - rv$code <- modifyList(rv$code,list(variable=attr(rv$data_variables, "code"))) + out <- data_type_filter(rv$data, input$column_filter) + rv$data_variables <- out + rv$code$variables <- attr(out, "code") # rv$code$modify[[length(rv$code$modify) + 1]] <- attr(rv$data, "code") }) @@ -9167,10 +9172,13 @@ server <- function(input, output, session) { }) output$code_variables <- shiny::renderUI({ - prismCodeBlock(paste0("#Variables filter\n", rv$code$variables)) + shiny::req(rv$code$variables) + out <- expression_string(rv$code$variables, assign.str = "df <- df |>\n") + prismCodeBlock(paste0("#Variables filter\n", out)) }) output$code_filter <- shiny::renderUI({ + shiny::req(rv$code$filter) prismCodeBlock(paste0("#Data filter\n", rv$code$filter)) }) diff --git a/inst/apps/FreesearchR/rsconnect/shinyapps.io/agdamsbo/freesearcheR.dcf b/inst/apps/FreesearchR/rsconnect/shinyapps.io/agdamsbo/freesearcheR.dcf index f0b83a1..9cf3c2a 100644 --- a/inst/apps/FreesearchR/rsconnect/shinyapps.io/agdamsbo/freesearcheR.dcf +++ b/inst/apps/FreesearchR/rsconnect/shinyapps.io/agdamsbo/freesearcheR.dcf @@ -5,6 +5,6 @@ account: agdamsbo server: shinyapps.io hostUrl: https://api.shinyapps.io/v1 appId: 13611288 -bundleId: 10098710 +bundleId: 10111316 url: https://agdamsbo.shinyapps.io/freesearcheR/ version: 1 diff --git a/inst/apps/FreesearchR/server.R b/inst/apps/FreesearchR/server.R index 04b1939..eefe63d 100644 --- a/inst/apps/FreesearchR/server.R +++ b/inst/apps/FreesearchR/server.R @@ -273,7 +273,7 @@ server <- function(input, output, session) { output$data_info <- shiny::renderUI({ shiny::req(data_filter()) - data_description(data_filter(),"The filtered data") + data_description(data_filter(), "The filtered data") }) ######### Create factor @@ -367,12 +367,13 @@ server <- function(input, output, session) { }) shiny::observeEvent(list( - input$column_filter#, + input$column_filter # , # rv$data ), { shiny::req(input$column_filter) - rv$data_variables <- data_type_filter(rv$data, input$column_filter) - rv$code <- modifyList(rv$code,list(variable=attr(rv$data_variables, "code"))) + out <- data_type_filter(rv$data, input$column_filter) + rv$data_variables <- out + rv$code$variables <- attr(out, "code") # rv$code$modify[[length(rv$code$modify) + 1]] <- attr(rv$data, "code") }) @@ -491,10 +492,13 @@ server <- function(input, output, session) { }) output$code_variables <- shiny::renderUI({ - prismCodeBlock(paste0("#Variables filter\n", rv$code$variables)) + shiny::req(rv$code$variables) + out <- expression_string(rv$code$variables, assign.str = "df <- df |>\n") + prismCodeBlock(paste0("#Variables filter\n", out)) }) output$code_filter <- shiny::renderUI({ + shiny::req(rv$code$filter) prismCodeBlock(paste0("#Data filter\n", rv$code$filter)) }) diff --git a/inst/apps/FreesearchR/ui.R b/inst/apps/FreesearchR/ui.R index ada8057..617688f 100644 --- a/inst/apps/FreesearchR/ui.R +++ b/inst/apps/FreesearchR/ui.R @@ -158,8 +158,12 @@ ui_elements <- list( shiny::tags$br(), shiny::tags$br(), shiny::uiOutput(outputId = "column_filter"), + shiny::helpText("Variable data type filtering."), + shiny::tags$br(), shiny::tags$br(), IDEAFilter::IDEAFilter_ui("data_filter"), + shiny::helpText("Observations level filtering."), + shiny::tags$br(), shiny::tags$br() ) ), @@ -177,8 +181,8 @@ ui_elements <- list( width = 9, shiny::tags$p( shiny::markdown("Below, are several options for simple data manipulation like update variables by renaming, creating new labels (for nicer tables in the report) and changing variable classes (numeric, factor/categorical etc.)."), - shiny::tags$p("There are also more advanced options to modify factor/categorical variables as well as create new factor from a continous variable or new variables with *R* code. At the bottom you can restore the original data."), - shiny::tags$p("Please note that data modifications are applied before any data or variable filtering is applied.") + shiny::markdown("There are also more advanced options to modify factor/categorical variables as well as create new factor from a continous variable or new variables with *R* code. At the bottom you can restore the original data."), + shiny::markdown("Please note that data modifications are applied before any data or variable filtering is applied.") ) ) ), @@ -199,6 +203,7 @@ ui_elements <- list( ), shiny::tags$br(), shiny::helpText("Reorder the levels of factor/categorical variables."), + shiny::tags$br() ), shiny::column( width = 4, @@ -208,7 +213,8 @@ ui_elements <- list( width = "100%" ), shiny::tags$br(), - shiny::helpText("Create factor/categorical variable from a continous variable (number/date/time).") + shiny::helpText("Create factor/categorical variable from a continous variable (number/date/time)."), + shiny::tags$br() ), shiny::column( width = 4, @@ -218,11 +224,11 @@ ui_elements <- list( width = "100%" ), shiny::tags$br(), - shiny::helpText(shiny::markdown("Create a new variable/column based on an *R*-expression.")) + shiny::helpText(shiny::markdown("Create a new variable/column based on an *R*-expression.")), + shiny::tags$br() ) ), shiny::tags$br(), - shiny::tags$br(), tags$h4("Compare modified data to original"), shiny::tags$br(), shiny::tags$p(