mirror of
https://github.com/agdamsbo/FreesearchR.git
synced 2025-09-12 09:59:39 +02:00
improved code export. not at 100 %
Some checks are pending
pkgdown.yaml / pkgdown (push) Waiting to run
Some checks are pending
pkgdown.yaml / pkgdown (push) Waiting to run
This commit is contained in:
parent
0994cb42ec
commit
68c93d94e4
5 changed files with 266 additions and 210 deletions
|
@ -1 +1 @@
|
||||||
app_version <- function()'250317_2113'
|
app_version <- function()'250318_0819'
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#### Current file: R//app_version.R
|
#### Current file: R//app_version.R
|
||||||
########
|
########
|
||||||
|
|
||||||
app_version <- function()'250317_2113'
|
app_version <- function()'250318_0819'
|
||||||
|
|
||||||
|
|
||||||
########
|
########
|
||||||
|
@ -7539,17 +7539,7 @@ server <- function(input, output, session) {
|
||||||
# rv$data <- rv$data_original |> default_parsing()
|
# rv$data <- rv$data_original |> default_parsing()
|
||||||
# })
|
# })
|
||||||
|
|
||||||
######### Overview
|
|
||||||
|
|
||||||
data_summary_server(
|
|
||||||
id = "data_summary",
|
|
||||||
data = shiny::reactive({
|
|
||||||
rv$data_filtered
|
|
||||||
}),
|
|
||||||
color.main = "#2A004E",
|
|
||||||
color.sec = "#C62300",
|
|
||||||
pagination = 20
|
|
||||||
)
|
|
||||||
|
|
||||||
#########
|
#########
|
||||||
######### Modifications
|
######### Modifications
|
||||||
|
@ -7622,7 +7612,94 @@ server <- function(input, output, session) {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
######### Show result
|
|
||||||
|
######### Subset, rename, reclass
|
||||||
|
|
||||||
|
updated_data <- update_variables_server(
|
||||||
|
id = "modal_variables",
|
||||||
|
data = shiny::reactive(rv$data),
|
||||||
|
return_data_on_init = FALSE
|
||||||
|
)
|
||||||
|
|
||||||
|
shiny::observeEvent(updated_data(), {
|
||||||
|
rv$data <- updated_data()
|
||||||
|
rv$code$modify[[length(rv$code$modify) + 1]] <- attr(rv$data, "code")
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
######### Data filter
|
||||||
|
# IDEAFilter has the least cluttered UI, but might have a License issue
|
||||||
|
data_filter <- IDEAFilter::IDEAFilter("data_filter",
|
||||||
|
data = shiny::reactive(rv$data),
|
||||||
|
verbose = TRUE
|
||||||
|
)
|
||||||
|
|
||||||
|
shiny::observeEvent(
|
||||||
|
list(
|
||||||
|
shiny::reactive(rv$data),
|
||||||
|
shiny::reactive(rv$data_original),
|
||||||
|
data_filter(),
|
||||||
|
regression_vars(),
|
||||||
|
input$complete_cutoff
|
||||||
|
),
|
||||||
|
{
|
||||||
|
### Save filtered data
|
||||||
|
rv$data_filtered <- data_filter()
|
||||||
|
|
||||||
|
### Save filtered data
|
||||||
|
rv$list$data <- data_filter() |>
|
||||||
|
REDCapCAST::fct_drop()
|
||||||
|
|
||||||
|
out <- gsub(
|
||||||
|
"filter", "dplyr::filter",
|
||||||
|
gsub(
|
||||||
|
"\\s{2,}", " ",
|
||||||
|
paste0(
|
||||||
|
capture.output(attr(rv$data_filtered, "code")),
|
||||||
|
collapse = " "
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
out <- strsplit(out, "%>%") |>
|
||||||
|
unlist() |>
|
||||||
|
(\(.x){
|
||||||
|
paste(c("data <- data", .x[-1], "REDCapCAST::fct_drop()"),
|
||||||
|
collapse = "|> \n "
|
||||||
|
)
|
||||||
|
})()
|
||||||
|
|
||||||
|
rv$code <- append_list(data = out, list = rv$code, index = "filter")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
# shiny::observeEvent(
|
||||||
|
# list(
|
||||||
|
# shiny::reactive(rv$data),
|
||||||
|
# shiny::reactive(rv$data_original),
|
||||||
|
# data_filter(),
|
||||||
|
# shiny::reactive(rv$data_filtered)
|
||||||
|
# ),
|
||||||
|
# {
|
||||||
|
#
|
||||||
|
# }
|
||||||
|
# )
|
||||||
|
|
||||||
|
######### Data preview
|
||||||
|
|
||||||
|
### Overview
|
||||||
|
|
||||||
|
data_summary_server(
|
||||||
|
id = "data_summary",
|
||||||
|
data = shiny::reactive({
|
||||||
|
rv$data_filtered
|
||||||
|
}),
|
||||||
|
color.main = "#2A004E",
|
||||||
|
color.sec = "#C62300",
|
||||||
|
pagination = 20
|
||||||
|
)
|
||||||
|
|
||||||
tryCatch(
|
tryCatch(
|
||||||
{
|
{
|
||||||
output$table_mod <- toastui::renderDatagrid({
|
output$table_mod <- toastui::renderDatagrid({
|
||||||
|
@ -7646,17 +7723,6 @@ server <- function(input, output, session) {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# output$code <- renderPrint({
|
|
||||||
# attr(rv$data, "code")
|
|
||||||
# })
|
|
||||||
|
|
||||||
# updated_data <- datamods::update_variables_server(
|
|
||||||
updated_data <- update_variables_server(
|
|
||||||
id = "modal_variables",
|
|
||||||
data = reactive(rv$data),
|
|
||||||
return_data_on_init = FALSE
|
|
||||||
)
|
|
||||||
|
|
||||||
output$original_str <- renderPrint({
|
output$original_str <- renderPrint({
|
||||||
str(rv$data_original)
|
str(rv$data_original)
|
||||||
})
|
})
|
||||||
|
@ -7669,71 +7735,37 @@ server <- function(input, output, session) {
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
shiny::observeEvent(updated_data(), {
|
|
||||||
rv$data <- updated_data()
|
|
||||||
})
|
|
||||||
|
|
||||||
# IDEAFilter has the least cluttered UI, but might have a License issue
|
|
||||||
data_filter <- IDEAFilter::IDEAFilter("data_filter", data = reactive(rv$data), verbose = TRUE)
|
|
||||||
|
|
||||||
shiny::observeEvent(
|
|
||||||
list(
|
|
||||||
shiny::reactive(rv$data),
|
|
||||||
shiny::reactive(rv$data_original),
|
|
||||||
data_filter(),
|
|
||||||
regression_vars(),
|
|
||||||
input$complete_cutoff
|
|
||||||
),
|
|
||||||
{
|
|
||||||
rv$data_filtered <- data_filter()
|
|
||||||
|
|
||||||
rv$list$data <- data_filter() |>
|
|
||||||
REDCapCAST::fct_drop()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
shiny::observeEvent(
|
|
||||||
list(
|
|
||||||
shiny::reactive(rv$data),
|
|
||||||
shiny::reactive(rv$data_original),
|
|
||||||
data_filter(),
|
|
||||||
shiny::reactive(rv$data_filtered)
|
|
||||||
),
|
|
||||||
{
|
|
||||||
out <- gsub(
|
|
||||||
"filter", "dplyr::filter",
|
|
||||||
gsub(
|
|
||||||
"\\s{2,}", " ",
|
|
||||||
paste0(
|
|
||||||
capture.output(attr(rv$data_filtered, "code")),
|
|
||||||
collapse = " "
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
out <- strsplit(out, "%>%") |>
|
|
||||||
unlist() |>
|
|
||||||
(\(.x){
|
|
||||||
paste(c("data", .x[-1]), collapse = "|> \n ")
|
|
||||||
})()
|
|
||||||
|
|
||||||
rv$code <- append_list(data = out, list = rv$code, index = "filter")
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
######### Code export
|
||||||
output$code_import <- shiny::renderPrint({
|
output$code_import <- shiny::renderPrint({
|
||||||
|
shiny::req(rv$code$import)
|
||||||
cat(rv$code$import)
|
cat(rv$code$import)
|
||||||
})
|
})
|
||||||
|
|
||||||
output$code_data <- shiny::renderPrint({
|
output$code_data <- shiny::renderPrint({
|
||||||
|
shiny::req(rv$code$modify)
|
||||||
ls <- rv$code$modify |> unique()
|
ls <- rv$code$modify |> unique()
|
||||||
out <- paste("data |> \n",
|
out <- paste("data <- data |>",
|
||||||
sapply(ls, \(.x) paste(deparse(.x), collapse = ",")),
|
sapply(ls, \(.x) paste(deparse(.x), collapse = ",")),
|
||||||
collapse="|> \n")
|
collapse = "|>"
|
||||||
|
) |>
|
||||||
|
(\(.x){
|
||||||
|
gsub(
|
||||||
|
"\\|>", "\\|> \n",
|
||||||
|
gsub(
|
||||||
|
"%>%", "",
|
||||||
|
gsub(
|
||||||
|
"\\s{2,}", " ",
|
||||||
|
gsub(",\\s{,},", ", ", .x)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
})()
|
||||||
cat(out)
|
cat(out)
|
||||||
})
|
})
|
||||||
|
|
||||||
output$code_filter <- shiny::renderPrint({
|
output$code_filter <- shiny::renderPrint({
|
||||||
|
shiny::req(rv$code$filter)
|
||||||
cat(rv$code$filter)
|
cat(rv$code$filter)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,6 @@ account: agdamsbo
|
||||||
server: shinyapps.io
|
server: shinyapps.io
|
||||||
hostUrl: https://api.shinyapps.io/v1
|
hostUrl: https://api.shinyapps.io/v1
|
||||||
appId: 13611288
|
appId: 13611288
|
||||||
bundleId:
|
bundleId: 9958862
|
||||||
url: https://agdamsbo.shinyapps.io/freesearcheR/
|
url: https://agdamsbo.shinyapps.io/freesearcheR/
|
||||||
version: 1
|
version: 1
|
||||||
|
|
|
@ -234,21 +234,6 @@ server <- function(input, output, session) {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
# shiny::observeEvent(input$reset_confirm, {
|
|
||||||
# rv$data <- rv$data_original |> default_parsing()
|
|
||||||
# })
|
|
||||||
|
|
||||||
######### Overview
|
|
||||||
|
|
||||||
data_summary_server(
|
|
||||||
id = "data_summary",
|
|
||||||
data = shiny::reactive({
|
|
||||||
rv$data_filtered
|
|
||||||
}),
|
|
||||||
color.main = "#2A004E",
|
|
||||||
color.sec = "#C62300",
|
|
||||||
pagination = 20
|
|
||||||
)
|
|
||||||
|
|
||||||
#########
|
#########
|
||||||
######### Modifications
|
######### Modifications
|
||||||
|
@ -321,7 +306,91 @@ server <- function(input, output, session) {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
######### Show result
|
######### Subset, rename, reclass
|
||||||
|
|
||||||
|
updated_data <- update_variables_server(
|
||||||
|
id = "modal_variables",
|
||||||
|
data = shiny::reactive(rv$data),
|
||||||
|
return_data_on_init = FALSE
|
||||||
|
)
|
||||||
|
|
||||||
|
shiny::observeEvent(updated_data(), {
|
||||||
|
rv$data <- updated_data()
|
||||||
|
rv$code$modify[[length(rv$code$modify) + 1]] <- attr(rv$data, "code")
|
||||||
|
})
|
||||||
|
|
||||||
|
######### Data filter
|
||||||
|
# IDEAFilter has the least cluttered UI, but might have a License issue
|
||||||
|
data_filter <- IDEAFilter::IDEAFilter("data_filter",
|
||||||
|
data = shiny::reactive(rv$data),
|
||||||
|
verbose = TRUE
|
||||||
|
)
|
||||||
|
|
||||||
|
shiny::observeEvent(
|
||||||
|
list(
|
||||||
|
shiny::reactive(rv$data),
|
||||||
|
shiny::reactive(rv$data_original),
|
||||||
|
data_filter(),
|
||||||
|
regression_vars(),
|
||||||
|
input$complete_cutoff
|
||||||
|
),
|
||||||
|
{
|
||||||
|
### Save filtered data
|
||||||
|
rv$data_filtered <- data_filter()
|
||||||
|
|
||||||
|
### Save filtered data
|
||||||
|
rv$list$data <- data_filter() |>
|
||||||
|
REDCapCAST::fct_drop()
|
||||||
|
|
||||||
|
out <- gsub(
|
||||||
|
"filter", "dplyr::filter",
|
||||||
|
gsub(
|
||||||
|
"\\s{2,}", " ",
|
||||||
|
paste0(
|
||||||
|
capture.output(attr(rv$data_filtered, "code")),
|
||||||
|
collapse = " "
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
out <- strsplit(out, "%>%") |>
|
||||||
|
unlist() |>
|
||||||
|
(\(.x){
|
||||||
|
paste(c("data <- data", .x[-1], "REDCapCAST::fct_drop()"),
|
||||||
|
collapse = "|> \n "
|
||||||
|
)
|
||||||
|
})()
|
||||||
|
|
||||||
|
rv$code <- append_list(data = out, list = rv$code, index = "filter")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
# shiny::observeEvent(
|
||||||
|
# list(
|
||||||
|
# shiny::reactive(rv$data),
|
||||||
|
# shiny::reactive(rv$data_original),
|
||||||
|
# data_filter(),
|
||||||
|
# shiny::reactive(rv$data_filtered)
|
||||||
|
# ),
|
||||||
|
# {
|
||||||
|
#
|
||||||
|
# }
|
||||||
|
# )
|
||||||
|
|
||||||
|
######### Data preview
|
||||||
|
|
||||||
|
### Overview
|
||||||
|
|
||||||
|
data_summary_server(
|
||||||
|
id = "data_summary",
|
||||||
|
data = shiny::reactive({
|
||||||
|
rv$data_filtered
|
||||||
|
}),
|
||||||
|
color.main = "#2A004E",
|
||||||
|
color.sec = "#C62300",
|
||||||
|
pagination = 20
|
||||||
|
)
|
||||||
|
|
||||||
tryCatch(
|
tryCatch(
|
||||||
{
|
{
|
||||||
output$table_mod <- toastui::renderDatagrid({
|
output$table_mod <- toastui::renderDatagrid({
|
||||||
|
@ -345,17 +414,6 @@ server <- function(input, output, session) {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# output$code <- renderPrint({
|
|
||||||
# attr(rv$data, "code")
|
|
||||||
# })
|
|
||||||
|
|
||||||
# updated_data <- datamods::update_variables_server(
|
|
||||||
updated_data <- update_variables_server(
|
|
||||||
id = "modal_variables",
|
|
||||||
data = reactive(rv$data),
|
|
||||||
return_data_on_init = FALSE
|
|
||||||
)
|
|
||||||
|
|
||||||
output$original_str <- renderPrint({
|
output$original_str <- renderPrint({
|
||||||
str(rv$data_original)
|
str(rv$data_original)
|
||||||
})
|
})
|
||||||
|
@ -368,67 +426,32 @@ server <- function(input, output, session) {
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
shiny::observeEvent(updated_data(), {
|
|
||||||
rv$data <- updated_data()
|
|
||||||
})
|
|
||||||
|
|
||||||
# IDEAFilter has the least cluttered UI, but might have a License issue
|
|
||||||
data_filter <- IDEAFilter::IDEAFilter("data_filter", data = reactive(rv$data), verbose = TRUE)
|
|
||||||
|
|
||||||
shiny::observeEvent(
|
|
||||||
list(
|
|
||||||
shiny::reactive(rv$data),
|
|
||||||
shiny::reactive(rv$data_original),
|
|
||||||
data_filter(),
|
|
||||||
regression_vars(),
|
|
||||||
input$complete_cutoff
|
|
||||||
),
|
|
||||||
{
|
|
||||||
rv$data_filtered <- data_filter()
|
|
||||||
|
|
||||||
rv$list$data <- data_filter() |>
|
|
||||||
REDCapCAST::fct_drop()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
shiny::observeEvent(
|
|
||||||
list(
|
|
||||||
shiny::reactive(rv$data),
|
|
||||||
shiny::reactive(rv$data_original),
|
|
||||||
data_filter(),
|
|
||||||
shiny::reactive(rv$data_filtered)
|
|
||||||
),
|
|
||||||
{
|
|
||||||
out <- gsub(
|
|
||||||
"filter", "dplyr::filter",
|
|
||||||
gsub(
|
|
||||||
"\\s{2,}", " ",
|
|
||||||
paste0(
|
|
||||||
capture.output(attr(rv$data_filtered, "code")),
|
|
||||||
collapse = " "
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
out <- strsplit(out, "%>%") |>
|
|
||||||
unlist() |>
|
|
||||||
(\(.x){
|
|
||||||
paste(c("data", .x[-1]), collapse = "|> \n ")
|
|
||||||
})()
|
|
||||||
|
|
||||||
rv$code <- append_list(data = out, list = rv$code, index = "filter")
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
######### Code export
|
||||||
output$code_import <- shiny::renderPrint({
|
output$code_import <- shiny::renderPrint({
|
||||||
|
shiny::req(rv$code$import)
|
||||||
cat(rv$code$import)
|
cat(rv$code$import)
|
||||||
})
|
})
|
||||||
|
|
||||||
output$code_data <- shiny::renderPrint({
|
output$code_data <- shiny::renderPrint({
|
||||||
|
shiny::req(rv$code$modify)
|
||||||
ls <- rv$code$modify |> unique()
|
ls <- rv$code$modify |> unique()
|
||||||
out <- paste("data |> \n",
|
out <- paste("data <- data |>",
|
||||||
sapply(ls, \(.x) paste(deparse(.x), collapse = ",")),
|
sapply(ls, \(.x) paste(deparse(.x), collapse = ",")),
|
||||||
collapse="|> \n")
|
collapse = "|>"
|
||||||
|
) |>
|
||||||
|
(\(.x){
|
||||||
|
gsub(
|
||||||
|
"\\|>", "\\|> \n",
|
||||||
|
gsub(
|
||||||
|
"%>%", "",
|
||||||
|
gsub(
|
||||||
|
"\\s{2,}", " ",
|
||||||
|
gsub(",\\s{,},", ", ", .x)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
})()
|
||||||
cat(out)
|
cat(out)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -549,7 +549,8 @@ ui_elements <- list(
|
||||||
),
|
),
|
||||||
shiny::br(),
|
shiny::br(),
|
||||||
shiny::br(),
|
shiny::br(),
|
||||||
shiny::tags$b("Code snippets:"),
|
shiny::h4("Code snippets"),
|
||||||
|
shiny::tags$p("Below are the code used to create the final data set. This can be saved for reproducibility. The code may not be 100 % correct, but kan be used for learning and example code to get started on coding yourself."),
|
||||||
shiny::verbatimTextOutput(outputId = "code_import"),
|
shiny::verbatimTextOutput(outputId = "code_import"),
|
||||||
shiny::verbatimTextOutput(outputId = "code_data"),
|
shiny::verbatimTextOutput(outputId = "code_data"),
|
||||||
shiny::verbatimTextOutput(outputId = "code_filter"),
|
shiny::verbatimTextOutput(outputId = "code_filter"),
|
||||||
|
|
Loading…
Add table
Reference in a new issue