0
votes

I have created the following dataframe using R

datelist<-seq(as.Date('2011-01-01'),as.Date('2011-01-31'),by = 1)

df<-as.data.frame(datelist)
df$New<-1:nrow(df)

Next I have created a UI and Server using shiny to read the table

library(shiny)
UI<-fluidPage(fileInput("file", "Browse",
                    accept = c("text/csv",
                               "text/comma-separated-values,text/plain",
                               ".csv")),dateInput(inputId = "Cutoffdate", 
    label = "Cut Off Date"),
          tableOutput(outputId = "Table1"))

Server<-function(input, output, session){

   options(shiny.maxRequestSize=100*1024^2) 

   output$Table1<-renderTable({

   infile <- input$file
   if (is.null(infile)) {
   # User has not uploaded a file yet
   return(NULL)
   }

    df<-readxl::read_xlsx(input$file$datapath)
   })

shinyApp(UI, Server)

Instead of Year month date the table output gives a series of numbers. I have tried using ymd from lubridate but that doesn't help. Is there a way to coax the data into ymd inside the reactive environment in R

1
Excel may be storing the date as an integer if you have made the column type as Date. It has it's own format for this and might change. I recommend storing the date as a character string, and converting it using as.Date inside RRohit
Are you exporting df to excel/csv after creating it? And then reading it back in R?Vishesh Shrivastav
@VisheshShrivastav yes. But Even if stored as a date externally it only produces thisRaghavan vmvs

1 Answers

1
votes

Since your fileInput accepts only .csv formats, I'd suggest using read.table to read in the data. You can specify column formats using colClasses paramter inside the read.table function.

df <- read.table(input$file$datapath, header = TRUE, sep = ","
                 colClasses = c("Date", "factor" # ... etc
                 ))
    )