2
library(shiny)
library(rhandsontable)

ui = shinyUI(fluidPage(
  fluidRow(wellPanel(
    rHandsontableOutput("hot"),
    actionButton(inputId="enter",label="enter")
  ))
))


server=function(input,output){

  DF=data.frame(Code=c(1,2,3),Amount=c(NA,NA,NA))

  output$hot=renderRHandsontable(rhandsontable(DF,readOnly=F))

  observeEvent(input$enter, {
    DF=hot_to_r(input$hot)
    print(DF)
  })
}

shinyApp(ui = ui, server = server)

嗨,我想从闪亮的 rhansontable 输入。但是,当列的单元格充满 NA 时,无法编辑单元格。这些可以解决吗?谢谢


还有当我像这样更改数据类型时

output$hot=renderRHandsontable(rhandsontable(DF,readOnly=F) %>% hot_col(col = "Amount", type = "numeric"))

可以编辑单元格中的值。但是,当我使用 'DF=hot_to_r(input$hot)' 时,这些值似乎没有保存在 DF 中。

4

2 回答 2

3

根据链接,您必须将 NA 转换为字符。所以你需要做这样的事情:

 server=function(input,output){

    DF=data.frame(Code=c(1,2,3),Amount=as.character(c(NA,NA,NA)))

    output$hot=renderRHandsontable(rhandsontable(DF, readOnly = FALSE) %>%
                                     hot_col("Amount", type = "numeric"))

    observeEvent(input$enter, {
      DF=hot_to_r(input$hot)
      print(DF)
    })
  }
于 2017-04-24T06:06:47.320 回答
1

将此添加到 DF

  DF=data.frame(Code=c(1,2,3),Amount=c(NA,NA,NA))

  DF[is.na(DF)] <- ""
于 2017-04-24T07:02:17.280 回答