jrowen / rhandsontable

A htmlwidgets implementation of Handsontable.js
http://jrowen.github.io/rhandsontable/
Other
384 stars 148 forks source link

Locking rhandontable #176

Open marciz opened 7 years ago

marciz commented 7 years ago

Is it possible to lock rhandontable for editing while updates are not finished?

Example below causes problems if values are input while shiny is updating the table

library(shiny)
library(rhandsontable)
library(dplyr)

df.0 <- data.frame(
  X1 = rep(NA_integer_, 10),
  X2 = NA_integer_,
  stringsAsFactors = F)

calc.df <- function(fdf){
  print(paste('calc', Sys.time()))

  Sys.sleep(3)

  fdf <- fdf %>%
    mutate(
      Y1 = X2 + X1,
      Y2 = ifelse(Y1 > 10, 10, 20)
    )

  return(fdf)
}

ui <- shinyUI(
  basicPage(
    rHandsontableOutput("hot.df")
  )
)

server <- function(input, output, session) {

  output$hot.df <- renderRHandsontable({
    print(paste('hot', Sys.time()))

    df <- df.0

    if(!is.null(input$hot.df)) {
      df <- hot_to_r(input$hot.df)
    }

    df <- calc.df(df)

    rhandsontable(df, useTypes = TRUE)

  })

  session$onSessionEnded(function() {
    stopApp()
  })
}

shinyApp(ui = ui, server = server)
bklingen commented 7 years ago

I often experience the same problem. I tried to use debounce() but with little success.