Reputation: 393
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)
Hi, I want to input from rhansontable which is in shiny. However, When column's cells are full of NA, the cells cannot be edited. can these be solved? Thanks
also that when I changed the data type like this
output$hot=renderRHandsontable(rhandsontable(DF,readOnly=F) %>% hot_col(col = "Amount", type = "numeric"))
the values in the cells can be edited. However, when I use 'DF=hot_to_r(input$hot)', the values seems like not saving in the DF.
Upvotes: 2
Views: 2002
Reputation: 29417
Add this to the DF
DF=data.frame(Code=c(1,2,3),Amount=c(NA,NA,NA))
DF[is.na(DF)] <- ""
Upvotes: 1
Reputation: 7704
According to this link, you will have to convert NA to characters. So you need to do something like this:
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)
})
}
Upvotes: 3