Как решить 'coerceValue' ошибка при использовании фрейма данных? - PullRequest
0 голосов
/ 02 июля 2019
 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 редактирует и сохраняет мой новый ввод?

1 Ответ

0 голосов
/ 02 июля 2019

Быстрый вопрос: вы, кажется, используете большую часть примера из здесь , но не все.Есть ли причина для этого?Вы можете использовать там код, как показано ниже, который проще:

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: target = "cell", как указано Стефан Лоран .

...