mirror of
https://github.com/agdamsbo/FreesearchR.git
synced 2025-09-12 01:49:39 +02:00
polished redcap import and code export
This commit is contained in:
parent
1613386096
commit
1b45c3fabf
2 changed files with 66 additions and 13 deletions
|
@ -200,9 +200,12 @@ m_redcap_readServer <- function(id) {
|
||||||
)
|
)
|
||||||
|
|
||||||
# browser()
|
# browser()
|
||||||
shiny::withProgress({
|
shiny::withProgress(
|
||||||
imported <- try(rlang::exec(REDCapR::redcap_metadata_read, !!!parameters), silent = TRUE)
|
{
|
||||||
},message = paste("Connecting to",data_rv$uri))
|
imported <- try(rlang::exec(REDCapR::redcap_metadata_read, !!!parameters), silent = TRUE)
|
||||||
|
},
|
||||||
|
message = paste("Connecting to", data_rv$uri)
|
||||||
|
)
|
||||||
|
|
||||||
## TODO: Simplify error messages
|
## TODO: Simplify error messages
|
||||||
if (inherits(imported, "try-error") || NROW(imported) < 1 || ifelse(is.list(imported), !isTRUE(imported$success), FALSE)) {
|
if (inherits(imported, "try-error") || NROW(imported) < 1 || ifelse(is.list(imported), !isTRUE(imported$success), FALSE)) {
|
||||||
|
@ -228,7 +231,7 @@ m_redcap_readServer <- function(id) {
|
||||||
status = "success",
|
status = "success",
|
||||||
include_data_alert(
|
include_data_alert(
|
||||||
see_data_text = "Click to see data dictionary",
|
see_data_text = "Click to see data dictionary",
|
||||||
dataIdName = "see_data",
|
dataIdName = "see_dd",
|
||||||
extra = tags$p(
|
extra = tags$p(
|
||||||
tags$b(phosphoricons::ph("check", weight = "bold"), "Connected to server!"),
|
tags$b(phosphoricons::ph("check", weight = "bold"), "Connected to server!"),
|
||||||
glue::glue("The {data_rv$info$project_title} project is loaded.")
|
glue::glue("The {data_rv$info$project_title} project is loaded.")
|
||||||
|
@ -254,8 +257,8 @@ m_redcap_readServer <- function(id) {
|
||||||
output$connect_success <- shiny::reactive(identical(data_rv$dd_status, "success"))
|
output$connect_success <- shiny::reactive(identical(data_rv$dd_status, "success"))
|
||||||
shiny::outputOptions(output, "connect_success", suspendWhenHidden = FALSE)
|
shiny::outputOptions(output, "connect_success", suspendWhenHidden = FALSE)
|
||||||
|
|
||||||
shiny::observeEvent(input$see_data, {
|
shiny::observeEvent(input$see_dd, {
|
||||||
datamods::show_data(
|
show_data(
|
||||||
purrr::pluck(data_rv$dd_list, "data"),
|
purrr::pluck(data_rv$dd_list, "data"),
|
||||||
title = "Data dictionary",
|
title = "Data dictionary",
|
||||||
type = "modal",
|
type = "modal",
|
||||||
|
@ -264,6 +267,17 @@ m_redcap_readServer <- function(id) {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
shiny::observeEvent(input$see_data, {
|
||||||
|
show_data(
|
||||||
|
# purrr::pluck(data_rv$dd_list, "data"),
|
||||||
|
data_rv$data,
|
||||||
|
title = "Imported data set",
|
||||||
|
type = "modal",
|
||||||
|
show_classes = FALSE,
|
||||||
|
tags$b("Preview:")
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
arms <- shiny::reactive({
|
arms <- shiny::reactive({
|
||||||
shiny::req(input$api)
|
shiny::req(input$api)
|
||||||
shiny::req(data_rv$uri)
|
shiny::req(data_rv$uri)
|
||||||
|
@ -378,13 +392,24 @@ m_redcap_readServer <- function(id) {
|
||||||
imported <- try(rlang::exec(REDCapCAST::read_redcap_tables, !!!parameters), silent = TRUE)
|
imported <- try(rlang::exec(REDCapCAST::read_redcap_tables, !!!parameters), silent = TRUE)
|
||||||
})
|
})
|
||||||
|
|
||||||
code <- rlang::call2("read_redcap_tables",
|
parameters_code <- parameters[c("uri", "fields", "events", "raw_or_label", "filter_logic")]
|
||||||
!!!utils::modifyList(parameters, list(token = "PERSONAL_API_TOKEN")), ,
|
|
||||||
|
code <- rlang::call2(
|
||||||
|
"easy_redcap",
|
||||||
|
!!!utils::modifyList(
|
||||||
|
parameters_code,
|
||||||
|
list(
|
||||||
|
data_format = ifelse(
|
||||||
|
input$data_type == "long" && !is.null(input$data_type),
|
||||||
|
"long",
|
||||||
|
"wide"
|
||||||
|
),
|
||||||
|
project.name = simple_snake(data_rv$info$project_title)
|
||||||
|
)
|
||||||
|
),
|
||||||
.ns = "REDCapCAST"
|
.ns = "REDCapCAST"
|
||||||
)
|
)
|
||||||
|
|
||||||
# browser()
|
|
||||||
|
|
||||||
if (inherits(imported, "try-error") || NROW(imported) < 1) {
|
if (inherits(imported, "try-error") || NROW(imported) < 1) {
|
||||||
data_rv$data_status <- "error"
|
data_rv$data_status <- "error"
|
||||||
data_rv$data_list <- NULL
|
data_rv$data_list <- NULL
|
||||||
|
@ -453,9 +478,17 @@ m_redcap_readServer <- function(id) {
|
||||||
datamods:::insert_alert(
|
datamods:::insert_alert(
|
||||||
selector = ns("retrieved"),
|
selector = ns("retrieved"),
|
||||||
status = data_rv$data_status,
|
status = data_rv$data_status,
|
||||||
tags$p(
|
# tags$p(
|
||||||
tags$b(phosphoricons::ph("check", weight = "bold"), "Success!"),
|
# tags$b(phosphoricons::ph("check", weight = "bold"), "Success!"),
|
||||||
data_rv$data_message
|
# data_rv$data_message
|
||||||
|
# ),
|
||||||
|
include_data_alert(
|
||||||
|
see_data_text = "Click to see the imported data",
|
||||||
|
dataIdName = "see_data",
|
||||||
|
extra = tags$p(
|
||||||
|
tags$b(phosphoricons::ph("check", weight = "bold"), data_rv$data_message)
|
||||||
|
),
|
||||||
|
btn_show_data = TRUE
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|
20
man/simple_snake.Rd
Normal file
20
man/simple_snake.Rd
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/helpers.R
|
||||||
|
\name{simple_snake}
|
||||||
|
\alias{simple_snake}
|
||||||
|
\title{Simplified version of the snakecase packages to_snake_case}
|
||||||
|
\usage{
|
||||||
|
simple_snake(data)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{data}{character string vector}
|
||||||
|
}
|
||||||
|
\value{
|
||||||
|
vector
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Simplified version of the snakecase packages to_snake_case
|
||||||
|
}
|
||||||
|
\examples{
|
||||||
|
c("foo bar", "fooBar21", "!!Foo'B'a-r", "foo_bar", "F OO bar") |> simple_snake()
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue