-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
53 lines (49 loc) · 1.28 KB
/
app.R
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
library(shiny)
library(readxl)
# Define UI for data upload app ----
ui <- fluidPage(
# App title ----
titlePanel("Uploading Files"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Select a file ----
fileInput(
inputId = "file1",
label = "Choose XLSX file to upload",
multiple = FALSE,
accept = ".xlsx")
),
# Horizontal line ----
tags$hr()
),
# Main panel for displaying outputs ----
mainPanel(
# Output: Data file ----
tableOutput("contents")
)
)
# Define server logic to read selected file ----
server <- function(input, output) {
output$contents <- renderTable({
# input$file1 will be NULL initially. After the user selects
# and uploads a file, head of that data file by default,
# or all rows if selected, will be shown.
req(input$file1)
# when reading semicolon separated files,
# having a comma separator causes `read.csv` to error
tryCatch(
{
df <- read_xlsx(path = input$file1$datapath, sheet = 3)
},
error = function(e) {
# return a safeError if a parsing error occurs
stop(safeError(e))
}
)
df
})
}
# Create Shiny app ----
shinyApp(ui, server)