【发布时间】:2018-11-09 12:16:08
【问题描述】:
我使用 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)
接下来我创建了一个 UI 和服务器,使用 shiny 来读取表格
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)
表格输出给出了一系列数字,而不是年份月份日期。我曾尝试使用 lubridate 的 ymd 但这没有帮助。有没有办法在 R
的反应性环境中将数据哄骗到 ymd【问题讨论】:
-
如果您将列类型设为日期,Excel 可能会将日期存储为整数。它有自己的格式并且可能会改变。我建议将日期存储为字符串,并在 R 中使用
as.Date进行转换 -
df创建后是否将其导出到 excel/csv?然后用 R 读回来? -
@VisheshShrivastav 是的。但即使在外部存储为日期,它也只会产生这个