【问题标题】:input from rhandsontable in shiny issuesrhandsontable 在闪亮问题中的输入
【发布时间】:2017-09-20 16:33:38
【问题描述】:
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 中。

【问题讨论】:

    标签: r shiny rhandsontable


    【解决方案1】:

    根据this 链接,您必须将 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)
        })
      }
    

    【讨论】:

    • 不,我希望单元格在视图中保持为空。但我希望能够编辑单元格~
    • 将其更改为字符仍会在视图中显示一个空单元格,只有当您尝试编辑单元格时,它才会像前一种情况一样显示 NA。
    【解决方案2】:

    将此添加到 DF

      DF=data.frame(Code=c(1,2,3),Amount=c(NA,NA,NA))
    
      DF[is.na(DF)] <- ""
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-19
      • 2019-10-20
      • 2017-08-17
      • 1970-01-01
      • 2021-08-10
      • 2017-10-08
      • 1970-01-01
      • 2017-05-11
      相关资源
      最近更新 更多