【问题标题】:invalid dateinput output format [duplicate]无效的日期输入输出格式[重复]
【发布时间】:2018-07-03 07:58:24
【问题描述】:

在创建闪亮的应用程序以根据用户输入获取数据框时,我使用以下内容,效果非常好:

library(shiny)
ui <- fluidPage(
  textInput("name", "Comnnay Name"),

  textInput("income", "Income"),

  textInput("expenditure", "Expenditure"),

  dateInput("date", h3("Date input"),value = Sys.Date()  , min = "0000-01-01",
            max = Sys.Date(), format = "dd/mm/yy"),

  #Table showing what is there in the data frame
  tableOutput("table"),
  #Button which appends row to the existing dataframe
  actionButton("Action", "Submit"),

  #Button to save the file
  downloadButton('downloadData', 'Download')


)

library(shiny)


server <- function(input, output){
  #Global variable to save the data
  Data <- data.frame()

  Results <- reactive(data.frame(input$name, input$income, input$expenditure,
                                 input$date , Sys.Date()))  

  #To append the row and display in the table when the submit button is clicked
  observeEvent(input$Action,{
    #Append the row in the dataframe
    Data <<- rbind(Data,Results()) 
    #Display the output in the table
    output$table <- renderTable(Data)
  })



  output$downloadData <- downloadHandler(

    # Create the download file name
    filename = function() {
      paste("data-", Sys.Date(), ".csv", sep="")
    },
    content = function(file) {

      write.csv(Data, file)         # put Data() into the download file
      })                          

}                                                                                  

shinyApp(ui = ui, server = server)

但是当我按下提交按钮时,它不会以我想要的格式打印日期

如何更改输出版本。还是我必须特别指定一些东西?谢谢。

【问题讨论】:

    标签: r datetime shiny


    【解决方案1】:

    大多数语言中的所有日期都是数字,这是意料之中的。如果你想要字符串简单地解析成它

     Results <- reactive(data.frame(input$name, input$income, input$expenditure,
                                     as.character(input$date), as.character(Sys.Date())))   
    

    【讨论】:

      猜你喜欢
      • 2020-02-05
      • 1970-01-01
      • 2014-08-14
      • 1970-01-01
      • 2023-03-31
      • 2021-02-21
      • 2015-03-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多