dommer
dommer

Reputation: 19810

How do I handle an empty table with rhandsontable in Shiny?

When the last row in my rhandsondtable is deleted I get the following error:

Warning: Error in matrix: 'data' must be of a vector type, was 'NULL'
Stack trace (innermost first):
    61: matrix
    60: <Anonymous>
    59: do.call
    58: hot_to_r
    57: observerFunc [#64]
    2: runApp
    1: editTable [#126]

Same thing happens when I run the code in this blog post. I'm using this code to experiment.

I want to be able to prevent this. I'm open to different options, e.g.

I've tried using the minSpareRows option, but this results in the following error

Warning: Error in row.names<-.data.frame: invalid 'row.names' length
Stack trace (innermost first):
    63: row.names<-.data.frame
    62: row.names<-
    61: rownames<-
    60: <Anonymous>
    59: do.call
    58: hot_to_r
    57: observerFunc [#64]
    2: runApp
    1: editTable [#127]

I don't now hot to check if the input$hot has rows in it and, as the hot_to_r function is the one failing, I can't use the data frame to do it.

Any help on how to deal with my "empty" table problem would be appreciated.

Upvotes: 0

Views: 1115

Answers (1)

Xiongbing Jin
Xiongbing Jin

Reputation: 12097

input$hot is a list that contains three items, with the first item input$hot$data containing the table data. So you can check length(input$hot$data) to determine how many rows remain.

Upvotes: 2

Related Questions