| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/input-file.R |
| 3 |
\name{fileInput} |
| 4 |
\alias{fileInput} |
| 5 |
\title{File Upload Control} |
| 6 |
\usage{ |
| 7 |
fileInput( |
| 8 |
inputId, |
| 9 |
label, |
| 10 |
multiple = FALSE, |
| 11 |
accept = NULL, |
| 12 |
width = NULL, |
| 13 |
buttonLabel = "Browse...", |
| 14 |
placeholder = "No file selected", |
| 15 |
capture = NULL |
| 16 |
) |
| 17 |
} |
| 18 |
\arguments{ |
| 19 |
\item{inputId}{The \code{input} slot that will be used to access the value.} |
| 20 |
|
| 21 |
\item{label}{Display label for the control, or \code{NULL} for no label.} |
| 22 |
|
| 23 |
\item{multiple}{Whether the user should be allowed to select and upload |
| 24 |
multiple files at once. \strong{Does not work on older browsers, including |
| 25 |
Internet Explorer 9 and earlier.}} |
| 26 |
|
| 27 |
\item{accept}{A character vector of "unique file type specifiers" which gives |
| 28 |
the browser a hint as to the type of file the server expects. Many browsers |
| 29 |
use this prevent the user from selecting an invalid file. |
| 30 |
|
| 31 |
A unique file type specifier can be: |
| 32 |
\itemize{ |
| 33 |
\item A case insensitive extension like \code{.csv} or \code{.rds}. |
| 34 |
\item A valid MIME type, like \code{text/plain} or \code{application/pdf} |
| 35 |
\item One of \verb{audio/*}, \verb{video/*}, or \verb{image/*} meaning any audio, video, |
| 36 |
or image type, respectively. |
| 37 |
}} |
| 38 |
|
| 39 |
\item{width}{The width of the input, e.g. \code{'400px'}, or \code{'100\%'}; |
| 40 |
see \code{\link[=validateCssUnit]{validateCssUnit()}}.} |
| 41 |
|
| 42 |
\item{buttonLabel}{The label used on the button. Can be text or an HTML tag |
| 43 |
object.} |
| 44 |
|
| 45 |
\item{placeholder}{The text to show before a file has been uploaded.} |
| 46 |
|
| 47 |
\item{capture}{What source to use for capturing image, audio or video data. |
| 48 |
This attribute facilitates user access to a device's media capture |
| 49 |
mechanism, such as a camera, or microphone, from within a file upload |
| 50 |
control. |
| 51 |
|
| 52 |
A value of \code{user} indicates that the user-facing camera and/or microphone |
| 53 |
should be used. A value of \code{environment} specifies that the outward-facing |
| 54 |
camera and/or microphone should be used. |
| 55 |
|
| 56 |
By default on most phones, this will accept still photos or video. For |
| 57 |
still photos only, also use \code{accept="image/*"}. For video only, use |
| 58 |
\code{accept="video/*"}.} |
| 59 |
} |
| 60 |
\description{ |
| 61 |
Create a file upload control that can be used to upload one or more files. |
| 62 |
} |
| 63 |
\details{ |
| 64 |
Whenever a file upload completes, the corresponding input variable is set to |
| 65 |
a dataframe. See the \verb{Server value} section. |
| 66 |
|
| 67 |
Each time files are uploaded, they are written to a new random subdirectory |
| 68 |
inside of R's process-level temporary directory. The Shiny user session keeps |
| 69 |
track of all uploads in the session, and when the session ends, Shiny deletes |
| 70 |
all of the subdirectories where files where uploaded to. |
| 71 |
} |
| 72 |
\section{Server value}{ |
| 73 |
|
| 74 |
|
| 75 |
A \code{data.frame} that contains one row for each selected file, and following |
| 76 |
columns: |
| 77 |
\describe{ |
| 78 |
\item{\code{name}}{The filename provided by the web browser. This is |
| 79 |
\strong{not} the path to read to get at the actual data that was uploaded |
| 80 |
(see |
| 81 |
\code{datapath} column).} |
| 82 |
\item{\code{size}}{The size of the uploaded data, in |
| 83 |
bytes.} |
| 84 |
\item{\code{type}}{The MIME type reported by the browser (for example, |
| 85 |
\code{text/plain}), or empty string if the browser didn't know.} |
| 86 |
\item{\code{datapath}}{The path to a temp file that contains the data that was |
| 87 |
uploaded. This file may be deleted if the user performs another upload |
| 88 |
operation.} |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
\examples{ |
| 93 |
## Only run examples in interactive R sessions |
| 94 |
if (interactive()) { |
| 95 |
|
| 96 |
ui <- fluidPage( |
| 97 |
sidebarLayout( |
| 98 |
sidebarPanel( |
| 99 |
fileInput("file1", "Choose CSV File", accept = ".csv"), |
| 100 |
checkboxInput("header", "Header", TRUE) |
| 101 |
), |
| 102 |
mainPanel( |
| 103 |
tableOutput("contents") |
| 104 |
) |
| 105 |
) |
| 106 |
) |
| 107 |
|
| 108 |
server <- function(input, output) { |
| 109 |
output$contents <- renderTable({ |
| 110 |
file <- input$file1 |
| 111 |
ext <- tools::file_ext(file$datapath) |
| 112 |
|
| 113 |
req(file) |
| 114 |
validate(need(ext == "csv", "Please upload a csv file")) |
| 115 |
|
| 116 |
read.csv(file$datapath, header = input$header) |
| 117 |
}) |
| 118 |
} |
| 119 |
|
| 120 |
shinyApp(ui, server) |
| 121 |
} |
| 122 |
|
| 123 |
} |
| 124 |
\seealso{ |
| 125 |
Other input elements: |
| 126 |
\code{\link{actionButton}()}, |
| 127 |
\code{\link{checkboxGroupInput}()}, |
| 128 |
\code{\link{checkboxInput}()}, |
| 129 |
\code{\link{dateInput}()}, |
| 130 |
\code{\link{dateRangeInput}()}, |
| 131 |
\code{\link{numericInput}()}, |
| 132 |
\code{\link{passwordInput}()}, |
| 133 |
\code{\link{radioButtons}()}, |
| 134 |
\code{\link{selectInput}()}, |
| 135 |
\code{\link{sliderInput}()}, |
| 136 |
\code{\link{submitButton}()}, |
| 137 |
\code{\link{textAreaInput}()}, |
| 138 |
\code{\link{textInput}()}, |
| 139 |
\code{\link{varSelectInput}()} |
| 140 |
} |
| 141 |
\concept{input elements} |