我已经使用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和服务器来读取表格
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中?
答案 0 :(得分:1)
由于您的fileInput
仅接受.csv格式,因此建议您使用read.table
读取数据。您可以使用colClasses
函数内的read.table
参数指定列格式。
df <- read.table(input$file$datapath, header = TRUE, sep = ","
colClasses = c("Date", "factor" # ... etc
))
)