From 6549ba2c79b792fda7875df1d30b571f5a257b71 Mon Sep 17 00:00:00 2001 From: Matthew Grainger Date: Thu, 19 May 2022 09:56:20 +0200 Subject: [PATCH] Maybe we just need to simplify input a bit? #102 --- server.R | 18 ++++++++---------- ui.R | 43 ++++++------------------------------------- 2 files changed, 14 insertions(+), 47 deletions(-) diff --git a/server.R b/server.R index 0474ac4..5fa079f 100755 --- a/server.R +++ b/server.R @@ -58,16 +58,14 @@ shinyServer( # if CSV data are supplied, add them to data_internal observeEvent(input$sysmapdata_upload, { - data_internal$raw <- read.csv( - file = input$sysmapdata_upload$datapath, - header = input$header, - sep = input$sep, - dec = input$dec, - quote = input$quote, - fileEncoding = input$upload_encoding, - stringsAsFactors = F) - #data_internal$filtered <- data_internal$raw #instantiate filtered table with raw values - }) + inFile <- input$sysmapdata_upload + extension <- tools::file_ext(inFile$name) + filepath <- inFile$datapath + data_internal$raw <- switch(extension, + csv = readr::read_csv2(filepath), + xls = readxl::read_xls(filepath), + xlsx = readxl::read_xlsx(filepath)) + }) # if shapefile data are supplied, add them to data_internal observeEvent(input$shape, { diff --git a/ui.R b/ui.R index ea0d184..8d62260 100755 --- a/ui.R +++ b/ui.R @@ -83,7 +83,7 @@ body <- dashboardBody( label = h4("Which Data to Use?"), choices = list( "Sample Data" = "sample", - "Upload from .csv format (spreadsheet)" = "user", + "Upload from .csv, .xlsx or .xls format (spreadsheet)" = "user", "Upload from .shp format (shapefile)" = "shapefile" ), selected = "user" @@ -100,53 +100,22 @@ body <- dashboardBody( fluidRow( fileInput( "sysmapdata_upload", - label = "Choose CSV File", + label = "Choose spreadsheet File", multiple = FALSE, accept = c( - "text/csv", - "text/comma-separated-values,text/plain", - ".csv"), + ".csv",".xlsx",".xls"), placeholder = "Systematic Map Data (100 MB Limit)" )), fluidRow( column(12, wellPanel( - h5(strong("CSV Properties")), + h5(strong("File Properties")), # Input: Checkbox if file has header ---- checkboxInput("header", "Header row?", TRUE), - selectInput("upload_encoding", - label = "Select File Encoding", - choices = list("Default" = "", - "UTF-8", - "latin1", - "mac"), - selected = "" - ), - # Input: Select separator ---- - selectInput("sep", - "Field Separator", - choices = c( - ",", - ";", - Tab = "\t", - '|' - ), - selected = "," - ), - # Input: Select quotes ---- - selectInput( - "quote", - "Quote Delimiter", - choices = c( - None = "", - '"', - "'" - ), - selected = '"' - )))) - )), + ) + )))), conditionalPanel(condition = "input.sample_or_real == 'shapefile'", fluidRow(column( 12,