Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 输入日期和DT::dataTableOutput_R_Date_Shiny_Dt - Fatal编程技术网

R 输入日期和DT::dataTableOutput

R 输入日期和DT::dataTableOutput,r,date,shiny,dt,R,Date,Shiny,Dt,我是新来的闪亮,这似乎是一个惊人的工具,我正在尝试建立一个应用程序 我目前正在试图理解为什么DT::dataTableOutput命令无法读取“inputDate”字段。。。例如,当我在界面中输入2021-01-01时,该表在“简介\日期”列中显示数字“18628” 这是我的代码,任何想法都欢迎 提前感谢社区,如果您需要更多/更好的信息来回答,请随时告诉我 # Libraries to open library(shiny) library(DT) #

我是新来的闪亮,这似乎是一个惊人的工具,我正在尝试建立一个应用程序

我目前正在试图理解为什么DT::dataTableOutput命令无法读取“inputDate”字段。。。例如,当我在界面中输入2021-01-01时,该表在“简介\日期”列中显示数字“18628”

这是我的代码,任何想法都欢迎

提前感谢社区,如果您需要更多/更好的信息来回答,请随时告诉我


    # Libraries to open
    library(shiny)
    library(DT)
    
    # Save function
    saveData <- function(data) {
      data <- as.data.frame(t(data))
      if (exists("responses")) {
        responses <<- rbind(responses, data)
      } else {
        responses <<- data
      }
    }
    
    loadData <- function() {
      if (exists("responses")) {
        responses
      }
    }
    
    # Define the fields we want to save from the form
    fields <- c("introduction_date","fish_species","cohort_id","cohort_size","initial_weight","cage_id","harvest_weight","allow_transfer") #,"transfer_density","cage_destination")
    
    fish.names <- c("Dicentrarchus.labrax","Sparus.aurata","Argyrosomus.regius","Symphodus.ocellatus","Salmo.salar","Salmo.trutta","Oncorhynchus.mykiss")
    
    
    # Shiny app with 3 fields that the user can submit data for
    
    shinyApp(
      ui <- fluidPage(
        
        titlePanel("Project"),
        
        sidebarLayout(
          
          sidebarPanel(
            dateInput("introduction_date", "Date:", value = "2021-01-01", format = "yyyy-mm-dd"), 
            selectInput("fish_species", "fish species",
                        fish.names),
            numericInput("cohort_id", "cohort id", 10, min = 1, max = 100),
            numericInput("cohort_size", "cohort size", 20000, min = 1, max = 100000),
            sliderInput("initial_weight", "initial weight:",
                        0, 100, 15, ticks = FALSE),
            numericInput("cage_id", "cage id", 10, min = 1, max = 100), 
            sliderInput("harvest_weight", "harvest weight",
                        200, 5000, 300, ticks = FALSE),
            checkboxInput("allow_transfer", "allow transfer", FALSE),
            actionButton("submit", "submit"),
            actionButton("save_planning", "save planning", class = "btn-success"),
          ),
          
          mainPanel(
            tabsetPanel(
              tabPanel("location", plotOutput("location"),
                       ), 
              tabPanel("Planning", verbatimTextOutput("planning"),
                       DT::dataTableOutput("responses", width = 300), tags$hr(),
                       ),
              tabPanel("Table", tableOutput("table"))
            )
          )
        )
      ),
          
      server = function(input, output, session) {
        
        # Whenever a field is filled, aggregate all form data
        formData <- reactive({
          data <- sapply(fields, function(x) input[[x]])
          data
        })
        
        # When the Submit button is clicked, save the form data
        observeEvent(input$submit, {
          saveData(formData())
        })
        
        # Show the previous responses
        # (update with current response when Submit is clicked)
        output$responses <- DT::renderDataTable({
          input$submit
          loadData()
        })     
        
        # When the Submit button is clicked, save the form data
        observeEvent(input$save_plan, {
          stopApp()
        })
      }
    )


#图书馆开放
图书馆(闪亮)
图书馆(DT)
#保存功能

saveData根据您的评论和@denis的评论,将您的
formData
替换为:

 formData <- reactive({
      data <- sapply(fields, function(x) as.character(input[[x]]))
      data
    })

formData将
date
存储为日期,该日期是起始日期后天数的整数。要将其保留在表中,请使用
as.character()
将其转换为字符,谢谢您的回答。这可能会达到目的,但我仍然无法将输入转换为字符串?我尝试使用formdata,但它不起作用。很好,我尝试将as.character()放在双括号中是错误的…[[]]非常感谢denis和Michael Dewar,祝Stackoverflow长寿!