import-modal {datamods} | R Documentation |
Import from all sources
Description
Wrap all import modules into one, can be displayed inline or in a modal window..
Usage
import_ui(
id,
from = c("env", "file", "copypaste", "googlesheets", "url"),
file_extensions = c(".csv", ".txt", ".xls", ".xlsx", ".rds", ".fst", ".sas7bdat",
".sav")
)
import_server(
id,
validation_opts = NULL,
allowed_status = c("OK", "Failed", "Error"),
return_class = c("data.frame", "data.table", "tbl_df", "raw"),
read_fns = list()
)
import_modal(
id,
from,
title = i18n("Import data"),
size = "l",
file_extensions = c(".csv", ".txt", ".xls", ".xlsx", ".rds", ".fst", ".sas7bdat",
".sav")
)
Arguments
id |
Module's id |
from |
The import_ui & server to use, i.e. the method. There are 5 options to choose from. ("env", "file", "copypaste", "googlesheets", "url") |
file_extensions |
File extensions accepted by |
validation_opts |
|
allowed_status |
Vector of statuses allowed to confirm dataset imported,
if you want that all validation rules are successful before importing data use |
return_class |
Class of returned data: |
read_fns |
Named list with custom function(s) to read data:
|
title |
Modal window title. |
size |
Modal window size, default to |
Value
UI: HTML tags that can be included in shiny's UI
Server: a
list
with three slots:-
status: a
reactive
function returning the status:NULL
,error
orsuccess
. -
name: a
reactive
function returning the name of the imported data ascharacter
. -
data: a
reactive
function returning the importeddata.frame
.
-
Examples
library(shiny)
library(datamods)
ui <- fluidPage(
# Try with different Bootstrap version
theme = bslib::bs_theme(version = 5, preset = "bootstrap"),
fluidRow(
column(
width = 4,
checkboxGroupInput(
inputId = "from",
label = "From",
choices = c("env", "file", "copypaste", "googlesheets", "url"),
selected = c("file", "copypaste")
),
actionButton("launch_modal", "Launch modal window")
),
column(
width = 8,
tags$b("Imported data:"),
verbatimTextOutput(outputId = "name"),
verbatimTextOutput(outputId = "data"),
verbatimTextOutput(outputId = "str_data")
)
)
)
server <- function(input, output, session) {
observeEvent(input$launch_modal, {
req(input$from)
import_modal(
id = "myid",
from = input$from,
title = "Import data to be used in application"
)
})
imported <- import_server("myid", return_class = "tbl_df")
output$name <- renderPrint({
req(imported$name())
imported$name()
})
output$data <- renderPrint({
req(imported$data())
imported$data()
})
output$str_data <- renderPrint({
req(imported$data())
str(imported$data())
})
}
if (interactive())
shinyApp(ui, server)