From bf5142997b3b3b20103ea2e4f1fa3e5da3b6aff5 Mon Sep 17 00:00:00 2001 From: pvictor Date: Thu, 1 Sep 2022 14:46:41 +0200 Subject: [PATCH] added file_extensions arg to import_modal() --- R/import-modal.R | 15 +++++++++++---- man/import-modal.Rd | 18 ++++++++++++++++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/R/import-modal.R b/R/import-modal.R index c993f3b..6875468 100644 --- a/R/import-modal.R +++ b/R/import-modal.R @@ -6,6 +6,7 @@ #' @param id Module's id #' @param from The import_ui & server to use, i.e. the method. #' There are 5 options to choose from. ("env", "file", "copypaste", "googlesheets", "url") +#' @inheritParams import-file #' #' @template module-import #' @@ -18,7 +19,9 @@ #' #' @example examples/modal.R #' -import_ui <- function(id, from = c("env", "file", "copypaste", "googlesheets", "url")) { +import_ui <- function(id, + from = c("env", "file", "copypaste", "googlesheets", "url"), + file_extensions = c(".csv", ".txt", ".xls", ".xlsx", ".rds", ".fst", ".sas7bdat", ".sav")) { ns <- NS(id) from <- match.arg(from, several.ok = TRUE) @@ -34,7 +37,7 @@ import_ui <- function(id, from = c("env", "file", "copypaste", "googlesheets", " tabPanelBody( value = "file", tags$br(), - import_file_ui(id = ns("file"), title = NULL) + import_file_ui(id = ns("file"), title = NULL, file_extensions = file_extensions) ) } @@ -392,7 +395,11 @@ import_server <- function(id, #' @rdname import-modal #' @importFrom shiny modalDialog showModal #' @importFrom htmltools tags css -import_modal <- function(id, from, title = "Import data", size = "l") { +import_modal <- function(id, + from, + title = "Import data", + size = "l", + file_extensions = c(".csv", ".txt", ".xls", ".xlsx", ".rds", ".fst", ".sas7bdat", ".sav")) { showModal(modalDialog( title = tagList( tags$button( @@ -405,7 +412,7 @@ import_modal <- function(id, from, title = "Import data", size = "l") { ), title ), - import_ui(id, from), + import_ui(id, from, file_extensions = file_extensions), size = size, footer = NULL )) diff --git a/man/import-modal.Rd b/man/import-modal.Rd index af2e9a9..ce1f3e0 100644 --- a/man/import-modal.Rd +++ b/man/import-modal.Rd @@ -7,7 +7,12 @@ \alias{import_modal} \title{Import from all sources} \usage{ -import_ui(id, from = c("env", "file", "copypaste", "googlesheets", "url")) +import_ui( + id, + from = c("env", "file", "copypaste", "googlesheets", "url"), + file_extensions = c(".csv", ".txt", ".xls", ".xlsx", ".rds", ".fst", ".sas7bdat", + ".sav") +) import_server( id, @@ -16,7 +21,14 @@ import_server( return_class = c("data.frame", "data.table", "tbl_df") ) -import_modal(id, from, title = "Import data", size = "l") +import_modal( + id, + from, + title = "Import data", + size = "l", + file_extensions = c(".csv", ".txt", ".xls", ".xlsx", ".rds", ".fst", ".sas7bdat", + ".sav") +) } \arguments{ \item{id}{Module's id} @@ -24,6 +36,8 @@ import_modal(id, from, title = "Import data", size = "l") \item{from}{The import_ui & server to use, i.e. the method. There are 5 options to choose from. ("env", "file", "copypaste", "googlesheets", "url")} +\item{file_extensions}{File extensions accepted by \code{\link[shiny:fileInput]{shiny::fileInput()}}, can also be MIME type.} + \item{validation_opts}{\code{list} of arguments passed to [validation_server().} \item{allowed_status}{Vector of statuses allowed to confirm dataset imported,