Skip to content

Instantly share code, notes, and snippets.

@cdeterman
Created May 14, 2015 12:39
Show Gist options
  • Save cdeterman/a41cceadffa7907c505e to your computer and use it in GitHub Desktop.
Save cdeterman/a41cceadffa7907c505e to your computer and use it in GitHub Desktop.
SO 30177053
library(shiny)
library(tools)
library(XLConnect)
shinyServer(function(input, output){
filedata <- reactive({
infile <- input$templatedfile
if(is.null(infile)){
return(NULL)
}
ext <- file_ext(infile$name)
importedfile <-
switch(ext,
csv = read.csv(infile$datapath, stringsAsFactors=FALSE),
xlsx = , xls = readWorksheetFromFile(infile$datapath,
sheet=1,
check.names=FALSE),
stop("file extension not recognized"))
})
output$mytable <- renderTable({
filedata()
})
})
library(shiny)
shinyUI(
pageWithSidebar(
headerPanel("Importing CSV and XLSX files"),
sidebarPanel(
p("Demo Page"),
fileInput("templatedfile", label=h3("Please submit file"))
),
mainPanel(
tableOutput("mytable")
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment