Thanks @tmastny,
I still have not found a solution but I do have an idea of why it may be happening. If the supplied data.frame has entries with 2 decimal places in them then any alterations to 2 decimal places are stored. Not sure if rhandsontable is expecting an integer input if the other values appear to be not numeric?
If you try the below code you will see that the values are stored with diagonal value = 100.23 (does not work for 100.00):
library(rhandsontable)
library(shiny)
mat <- diag(x=100.23, ncol = 4, nrow = 4)
RData <- data.frame(mat)
colnames(RData) <- c("A","B","C","D")
rownames(RData) <- colnames(mat)
ui <- fluidPage(
titlePanel("Test"),
mainPanel(
rHandsontableOutput("hot")
)
)
server = function(input, output, session){
values <- reactiveValues()
observe({
if(!is.null(input$hot)){
values$new <- hot_to_r(input$hot)
}else{
values$new <- RData
}
print(values$new)
})
output$hot <- renderRHandsontable({
rhandsontable(values$new,readOnly = FALSE) %>% hot_cols(format = "0.00")
})
}
shinyApp(ui, server)
Maybe a solution would be to explicitly display 2 decimal places in the original data.frame? I am not sure if this is possible?
Thanks for your help!