0

我有一个与下图相同的数据表,当我单击随机行时,应用程序将崩溃,并收到以下错误消息:

数据表

Warning in widgetFunc() :
  renderDataTable ignores ... arguments when expr yields a datatable object; see ?renderDataTable
Warning: Unhandled error in observer: (list) object cannot be coerced to type 'logical'
observeEvent(input$responses_rows_selected)
ERROR: [on_request_read] connection reset by peer

我不确定此错误消息的含义。

服务器.r

CreateDefaultRecord <- function() {
  mydefault <- CastData(list(id = "0", name = "", used_shiny = FALSE, r_num_years = 4))
  return (mydefault)
}


 CastData <- function(data) {
   datar <- data.frame(name = data["name"], 
                       used_shiny = as.logical(data["used_shiny"]), 
                       r_num_years = as.integer(data["r_num_years"]),
                       stringsAsFactors = FALSE)

   rownames(datar) <- data["id"]
   return (datar)
 }

 UpdateInputs <- function(data, session) {
   updateTextInput(session, "id", value = unname(rownames(data)))
   updateTextInput(session, "name", value = unname(data["name"]))
   updateCheckboxInput(session, "used_shiny", value = as.logical(data["used_shiny"]))
   updateSliderInput(session, "r_num_years", value = as.integer(data["r_num_years"]))
 }

         # Select row in table -> show details in inputs
      observeEvent(input$responses_rows_selected, {
        if (length(input$responses_rows_selected) > 0) {
          data <- ReadData()[input$responses_rows_selected, ]
          UpdateInputs(data, session)
        }

      })

  # display table 

      output$responses <- DT::renderDataTable({

        #update after submit is clicked
        input$submit
        #update after delete is clicked
        input$delete
        DT::datatable(ReadData(), options = list(pageLength=3),colnames = c('ID' = 1), class = 'cell-border stripe')
      }, server = FALSE, selection = "single",
      colnames = unname(GetTableMetadata()$fields)[-1]
      ) 
4

2 回答 2

1

问题是因为在数据表中选择了多个行。我只是添加

selection = "single"

在 DT::datatable()

 DT::datatable(ReadData(),extensions = 'Responsive', options = list(pageLength=3),colnames = c('ID' = 1), class = 'cell-border stripe', selection = "single")
于 2015-12-08T03:01:51.943 回答
1

你能检查一下类型input$responses_rows_selected吗?在你的 data <- ReadData()[input$responses_rows_selected, ],input$responses_rows_selected既不是一个逻辑或数字向量告诉 R 如何对你的表进行子集化。也许 Shiny 只是将input$responses_rows_selected其视为一个字符向量(就像它经常做的那样),或者非常令人惊讶的是,正如错误中提到的 ( (list) object cannot be coerced to type 'logical') 那样,作为一个列表。

于 2015-11-26T12:40:31.330 回答