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