rhandsontable how to restrict max. rows count

Viewed 810

I have a rhandsontable in a shiny app, that has 2 rows. It uses reactiveValues() to load values inside of it. Creating additional rows by dragging a cell is prohibited with

fillHandle = list(direction='vertical', autoInsertRow=FALSE))

The user should be allowed to create additional rows through context menu, but no more than 10. I though of doing it with customOpts, where the user can add new rows untill nrow(table) == 10, but i'm very bad with javascript. I tried to do it differently (see the code below), but couldn't make it work. Also, is there a way to do it in another way?

Here is the snipped of code I have so far:

output$table <- renderRHandsontable({
  rhandsontable(data.frame(rv_values),
                fillHandle = list(direction='vertical', autoInsertRow=FALSE)) %>%
    hot_context_menu(allowRowEdit = TRUE, allowColEdit = FALSE)
})

I tried to manually change the allowRowEdit like this, but couldn't quite figure out how to make it work:

observeEvent(input$table, {
  if(nrow(hot_to_r(input$table)) > 10)
#magic happens here

})

Any ideas?

2 Answers
Related