Let the user copy data from Excel or text file then paste it into a text area to import it.
Arguments
- id
Module's ID.
- title
Module's title, if
TRUE
use the default title, useNULL
for no title or ashiny.tag
for a custom one.- name_field
Show or not a field to add a name to data (that is returned server-side).
- btn_show_data
Display or not a button to display data in a modal window if import is successful.
- show_data_in
Where to display data: in a
"popup"
or in a"modal"
window.- trigger_return
When to update selected data:
"button"
(when user click on button) or"change"
(each time user select a dataset in the list).- return_class
Class of returned data:
data.frame
,data.table
,tbl_df
(tibble) orraw
.- reset
A
reactive
function that when triggered resets the data.- fread_args
list
of additional arguments to pass todata.table::fread()
when reading data.
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(
tags$h3("Import data with copy & paste"),
fluidRow(
column(
width = 4,
import_copypaste_ui("myid")
),
column(
width = 8,
tags$b("Import status:"),
verbatimTextOutput(outputId = "status"),
tags$b("Name:"),
verbatimTextOutput(outputId = "name"),
tags$b("Data:"),
verbatimTextOutput(outputId = "data")
)
)
)
server <- function(input, output, session) {
imported <- import_copypaste_server("myid")
output$status <- renderPrint({
imported$status()
})
output$name <- renderPrint({
imported$name()
})
output$data <- renderPrint({
imported$data()
})
}
if (interactive())
shinyApp(ui, server)