I'm working with google forms to create a subscription form. As the "date" type question used in google forms is a bit confusing for people with little contact with technology (the people that are going to subscribe are at-risk teenagers), I chose to separate year, month and day of birth in three different questions and then unite then using as.Date. I would upload the .csv file generated by google forms using fileInput and renderTable to show the data.
This code works perfectly in the console
# read the file from my computer
df <- read_csv("~APAMI/R/base.csv")
colnames(df)<- c("day", "month", "year")
dn <- as.Date(with(df, paste("year", "month", "day",sep="-")), "%Y-%m-%d")
df$dn<-dn
df
But when I apply this code to shiny the date returns a number, not the date. I've tried to use lubridate and to use "as.character" instead of "paste" . I've tried to use the "origin" function in as.Date, as well as the POSIXc option. Got the same result.
I really can't use the "date" question in forms, because people are having a hard time filling the questionnaire and are putting the wrong birth date constantly.
UI
library(shiny)
library(readr)
library(date)
shinyUI(fluidPage(
titlePanel("Triagem da Inscrição para APAMI"),
sidebarLayout(
sidebarPanel(
fileInput('datafile', 'Base de Dados')
),
mainPanel(
tableOutput("tabela")
)
)
))
SERVER
library(shiny)
library(readr)
library(date)
shinyServer(function(input, output) {
output$tabela <- renderTable ({
inFile <- input$datafile
if(is.null(inFile))
return(NULL)
df <- read_csv(inFile$datapath)
colnames(df)<- c("year", "month", "day")
dn <- as.Date(with(df, paste(year, month, day,sep="-")), "%Y-%m-%d")
df$dn<-dn
df
})
})
What should I do?