【问题标题】:How to solve 'coerceValue'-error when using a data-frame?使用数据框时如何解决“coerceValue”错误?
【发布时间】:2019-07-02 11:43:48
【问题描述】:
 shinyApp(
  ui = fluidPage(
    DTOutput('x1')
  ),
  server = function(input, output, session) {
    x = iris
    output$x1 = renderDT(x, selection = 'none', editable = list(target = 'row', disable = list(columns=c(1,3,4))))

    proxy = dataTableProxy('x1')

    observeEvent(input$x1_cell_edit, {
      info = input$x1_cell_edit
      str(info)
      i = info$row
      j = info$col
      v = info$value
      x[i, j] <<- DT::coerceValue(v, x[i, j])
      replaceData(proxy, x, resetPaging = FALSE)  # important
    })
  }
)

我收到以下警告:

Warning in DT::coerceValue(v, x[i, j]) :
  The data type is not supported: data.frame

Warning: Error in [[: attempt to select less than one element in integerOneIndex

如何确保 coerceValue 正在编辑和保存我的新输入?

【问题讨论】:

  • 使用target = "cell"j = info$col + 1
  • target = "cell" 为我工作,谢谢!
  • target = "cell" 是正确的,但是 j = info$col + 1 是不正确的。将其保留为 j = info$col,因为 DT 会忽略行名列。

标签: r shiny dt


【解决方案1】:

快速提问:您似乎使用了here 中的大部分示例,但不是全部。这有什么原因吗?您可以使用那里的代码,如下所示,更简单:

library(shiny)
library(DT)
shinyApp(
    ui = fluidPage(
        DTOutput('x1')
    ),
    server = function(input, output, session) {
        x = iris
        output$x1 = renderDT(x, selection = 'none', editable = list(target = 'cell', disable = list(columns=c(1,3,4))))

        proxy = dataTableProxy('x1')

        observeEvent(input$x1_cell_edit, {
            info = input$x1_cell_edit
            str(info)
            x <<- editData(x, info)
            replaceData(proxy, x, resetPaging = FALSE)  # important
        })
    }
)

PS:Stéphane Laurent 提到的 target = "cell"。

【讨论】:

  • 你是对的。我正在使用该网站创建代码。我正在定制一点,所以我会越界。我会尽量遵守该指南。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-09-04
  • 1970-01-01
  • 2019-11-02
  • 2020-02-22
  • 1970-01-01
  • 1970-01-01
  • 2017-07-05
相关资源
最近更新 更多