0

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?

  • Possible duplicate of [R shiny different output between renderTable and renderDataTable](https://stackoverflow.com/questions/21548843/r-shiny-different-output-between-rendertable-and-renderdatatable) – Aurèle Oct 16 '19 at 13:35
  • 2
    It is a known issue with `renderTable` https://github.com/rstudio/shiny/issues/129 . See https://stackoverflow.com/questions/21548843/r-shiny-different-output-between-rendertable-and-renderdatatable for a workaround – Aurèle Oct 16 '19 at 13:37
  • Thank you for your contribution! – Araê Souza Oct 17 '19 at 12:28

1 Answers1

0

I used the function "strftime". By the way, I used "read.csv" instead of "read_csv", because I got an error when running your code.

dn <- strftime(paste(df$year, df$month, df$day,sep="-"), "%Y-%m-%d")
S Novogoratz
  • 388
  • 2
  • 14