R/app_file_input.R

if (interactive()) {

	ui <- fluidPage(
		sidebarLayout(
			sidebarPanel(
				fileInput("file1", "Choose CSV File",
									accept = c(
										"text/csv",
										"text/comma-separated-values,text/plain",
										".csv")
				),
				tags$hr(),
				checkboxInput("header", "Header", TRUE)
			),
			mainPanel(
				tableOutput("contents")
			)
		)
	)

	server <- function(input, output) {
		output$contents <- renderTable({
			# input$file1 will be NULL initially. After the user selects
			# and uploads a file, it will be a data frame with 'name',
			# 'size', 'type', and 'datapath' columns. The 'datapath'
			# column will contain the local filenames where the data can
			# be found.
			inFile <- input$file1

			if (is.null(inFile))
				return(NULL)

			read.csv(inFile$datapath, header = input$header)
		})
	}

	shinyApp(ui, server)
}
jstrunk001/oRganizeRS documentation built on May 9, 2019, 7:34 p.m.