- shiny.ui.input_file(id, label, *, multiple=False, accept=None, width=None, button_label='Browse...', placeholder='No file selected', capture=None)#
Create a file upload control that can be used to upload one or more files.
str) – An input id.
ForwardRef]]]]) – An input label.
bool) – Whether the user should be allowed to select and upload multiple files at once.
Unique file type specifier(s) which give the browser a hint as to the type of file the server expects. Many browsers use this to prevent the user from selecting an invalid file. Examples of valid values include:
A case insensitive extension like
A valid MIME type, like
image/*meaning any audio, video, or image type, respectively.
str]) – The CSS width, e.g. ‘400px’, or ‘100%’
str) – The label used on the button.
str) – The text to show on the input before a file has been uploaded.
Literal[‘environment’, ‘user’]]) – On mobile devices, this can be used to open the device’s camera for input. If “environment”, it will open the rear-facing camera. If “user”, it will open the front-facing camera. By default, it will accept either still photos or video. To accept only still photos, use
accept="image/*"; to accept only video, use
- Return type
A UI element.
A list of dictionaries (one for each file upload) with the following keys:
name: The filename provided by the web browser. This is not the path to read to get at the actual data that was uploaded (see ‘datapath’).
size: The size of the uploaded data, in bytes.
type: The MIME type reported by the browser (for example, ‘text/plain’), or empty string if the browser didn’t know.
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.
#| standalone: true #| components: [editor, viewer] #| layout: vertical #| viewerHeight: 400 from shiny import * from shiny.types import FileInfo import pandas as pd app_ui = ui.page_fluid( ui.layout_sidebar( ui.panel_sidebar( ui.input_file("file1", "Choose CSV File", accept=[".csv"], multiple=False), ui.input_checkbox("header", "Header", True), ), ui.panel_main(ui.output_ui("contents")), ) ) def server(input: Inputs, output: Outputs, session: Session): @output @render.ui def contents(): if input.file1() is None: return "Please upload a csv file" f: list[FileInfo] = input.file1() df = pd.read_csv(f["datapath"], header=0 if input.header() else None) return ui.HTML(df.to_html(classes="table table-striped")) app = App(app_ui, server)