mirror of
https://github.com/agdamsbo/FreesearchR.git
synced 2025-09-12 09:59:39 +02:00
clean up and ods multi sheet merge
This commit is contained in:
parent
49016a4aa8
commit
e3261ad328
1 changed files with 98 additions and 134 deletions
|
@ -1,9 +1,3 @@
|
||||||
# library(htmltools)
|
|
||||||
# library(shiny)
|
|
||||||
# library(shinyWidgets)
|
|
||||||
# library(rlang)
|
|
||||||
# library(readxl)
|
|
||||||
|
|
||||||
#' @title Import data from a file
|
#' @title Import data from a file
|
||||||
#'
|
#'
|
||||||
#' @description Let user upload a file and import data
|
#' @description Let user upload a file and import data
|
||||||
|
@ -242,46 +236,6 @@ import_file_server <- function(id,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# output$sheet <- shiny::renderUI({
|
|
||||||
# if (is_workbook(input$file$datapath)) {
|
|
||||||
# if (isTRUE(is_excel(input$file$datapath))) {
|
|
||||||
# choices <- readxl::excel_sheets(input$file$datapath)
|
|
||||||
# } else if (isTRUE(is_ods(input$file$datapath))) {
|
|
||||||
# choices <- readODS::ods_sheets(input$file$datapath)
|
|
||||||
# }
|
|
||||||
# selected <- choices[1]
|
|
||||||
#
|
|
||||||
# shiny::selectInput(
|
|
||||||
# inputId = ns("sheet"),
|
|
||||||
# label = datamods:::i18n("Select sheet(s) to import:"),
|
|
||||||
# choices = choices,
|
|
||||||
# selected = selected,
|
|
||||||
# width = "100%",
|
|
||||||
# multiple = TRUE
|
|
||||||
# )
|
|
||||||
# # shinyWidgets::pickerInput(
|
|
||||||
# # inputId = ns("sheet"),
|
|
||||||
# # label = datamods:::i18n("Select sheet(s) to import:"),
|
|
||||||
# # choices = choices,
|
|
||||||
# # selected = selected,
|
|
||||||
# # width = "100%",
|
|
||||||
# # multiple = TRUE
|
|
||||||
# # )
|
|
||||||
# }
|
|
||||||
# })
|
|
||||||
|
|
||||||
# observeEvent(
|
|
||||||
# input$sheet,
|
|
||||||
# {
|
|
||||||
# req(input$file)
|
|
||||||
# if (is_workbook(input$file$datapath) && is.null(shiny::req(input$sheet))) {
|
|
||||||
# temporary_rv$data <- NULL
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# )
|
|
||||||
|
|
||||||
observeEvent(
|
observeEvent(
|
||||||
list(
|
list(
|
||||||
input$file,
|
input$file,
|
||||||
|
@ -456,18 +410,28 @@ import_xls <- function(file, sheet, skip, na.strings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
import_ods <- function(file, sheet, skip, na.strings) {
|
import_ods <- function(file, sheet, skip, na.strings) {
|
||||||
|
tryCatch(
|
||||||
|
{
|
||||||
|
sheet |>
|
||||||
|
purrr::map(\(.x){
|
||||||
readODS::read_ods(
|
readODS::read_ods(
|
||||||
path = file,
|
path = file,
|
||||||
sheet = sheet,
|
sheet = .x,
|
||||||
skip = skip,
|
skip = skip,
|
||||||
na = na.strings
|
na = na.strings
|
||||||
)
|
)
|
||||||
|
}) |>
|
||||||
|
purrr::reduce(dplyr::full_join)
|
||||||
|
},
|
||||||
|
warning = function(warn) {
|
||||||
|
showNotification(paste0(warn), type = "warning")
|
||||||
|
},
|
||||||
|
error = function(err) {
|
||||||
|
showNotification(paste0(err), type = "err")
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
# import_xls(openxlsx2::read_xlsx("~/freesearcheR/dev/Test data/trials_redcap_sheets.xlsx"),)
|
|
||||||
# list()
|
|
||||||
|
|
||||||
|
|
||||||
#' @title Create a select input control with icon(s)
|
#' @title Create a select input control with icon(s)
|
||||||
#'
|
#'
|
||||||
#' @description Extend form controls by adding text or icons before,
|
#' @description Extend form controls by adding text or icons before,
|
||||||
|
@ -511,13 +475,16 @@ selectInputIcon <- function(inputId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#' Test app for the import_file module
|
||||||
|
#'
|
||||||
|
#' @rdname import-file_module
|
||||||
# library(shiny)
|
#'
|
||||||
# library(datamods)
|
#' @examples
|
||||||
|
#' \dontrun{
|
||||||
ui <- shiny::fluidPage(
|
#' import_file_demo_app()
|
||||||
|
#' }
|
||||||
|
import_file_demo_app <- function() {
|
||||||
|
ui <- shiny::fluidPage(
|
||||||
# theme = bslib::bs_theme(version = 5L),
|
# theme = bslib::bs_theme(version = 5L),
|
||||||
# theme = bslib::bs_theme(version = 5L, preset = "bootstrap"),
|
# theme = bslib::bs_theme(version = 5L, preset = "bootstrap"),
|
||||||
shiny::tags$h3("Import data from a file"),
|
shiny::tags$h3("Import data from a file"),
|
||||||
|
@ -542,9 +509,8 @@ ui <- shiny::fluidPage(
|
||||||
shiny::verbatimTextOutput(outputId = "data")
|
shiny::verbatimTextOutput(outputId = "data")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
server <- function(input, output, session) {
|
||||||
server <- function(input, output, session) {
|
|
||||||
imported <- import_file_server(
|
imported <- import_file_server(
|
||||||
id = "myid",
|
id = "myid",
|
||||||
show_data_in = "popup",
|
show_data_in = "popup",
|
||||||
|
@ -592,8 +558,6 @@ server <- function(input, output, session) {
|
||||||
output$data <- shiny::renderPrint({
|
output$data <- shiny::renderPrint({
|
||||||
imported$data()
|
imported$data()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FALSE) {
|
|
||||||
shiny::shinyApp(ui, server)
|
shiny::shinyApp(ui, server)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue