I'm unable to successfully change the class of a column that was uploaded via fileInput(). I've tried specifying the column type to a date in the "read_csv" argument, although that didn't work. I then tried using mutate and as.Date() after importing, but that didn't work either.
Note - the data that is being imported has the date in the format of "mm/dd/yyyy". The name of the column is "day." ultimately, I want to extract the month and year from the date using lubridate.
# setup sidebar
# -------------
sidebar <- dashboardSidebar(disable = FALSE,
sidebarMenu(
menuItem("Testing Tab",
tabName="testing_tab",
icon=icon("line-chart")),
menuItem("Excel Input",
tabName="excel_input",
icon=icon('filter'),
menuSubItem(icon = NULL,
fileInput("upload", "Upload"))
)
)
)
# setup dashboard body
# --------------------
body <- dashboardBody(
tabItems(
tabItem(tabName = "testing_tab",
column(width = 12,
tableOutput('testing_01')
)
)
)
)
# setup dashboard header & tie three components together
# ------------------------------------------------------
header <- dashboardHeader(title = "Testing")
myUI <- dashboardPage(header, sidebar, body)
# setup server
# ------------
mySERVER <- function(input, output, session) {
output$testing_01 <- renderTable({
req(input$upload)
test_01 <- read.csv(input$upload$datapath) %>%
clean_names() %>%
mutate(day = as.Date(day, format = '%m/%d/%y'))
})
}
# deploy app
# ----------
shinyApp(
ui = myUI,
server = mySERVER
)