rhandsontable
rhandsontable copied to clipboard
Renderer is making the table slow/slugish. Any fix?
I found that rhandsontable renderer
is pretty slow. I can not even control/click/scroll when I have added renderer inside the table.
Here is the data which I am using. My data has more than 100k rows and 10 columns. Sample data has appx 24k rows.
library(tidyverse)
library(rhandsontable)
set.seed(123)
df <- data.frame(col1 = c('A','A','A','A', 'B','B','B','B', 'C','C','C','C'),
col2 = c('flower','pet','bird','tree','flower','pet','bird','tree','flower','pet','bird','tree'),
col3 = sample(0:25, 12, replace = TRUE))
for (i in 1:10){
df <- rbind(df, df)
}
df1 <- df[order(df$col1, factor(df$col2,
levels = c('pet', 'tree', 'bird', 'flower'))),]
row.names(df1) <- NULL
df1$col1[duplicated(df1$col1)] <- ""
Here is the code for the rhandsontable:
editable_rows <- seq(1, nrow(df1), by = 4)
rhandsontable(df1, selectCallback = TRUE,
readOnly = TRUE, rowHeaders = FALSE,
digits = 0) %>%
hot_table(highlightRow = TRUE, stretchH = "all") %>%
hot_cols(fixedRowsTop = 1, format = "00",
renderer = "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
if(instance.getData()[row][0] != ''){
td.style.background = '#b3e0ff';
}
}") %>%
hot_row(editable_rows, readOnly = FALSE)
)
I also tried setting the first row of the table to bold. Still the same issue. Surprisingly, when I remove the renderer, everything works smoothly. Here is the code for table where I have removed the renderer:
editable_rows <- seq(1, nrow(df1), by = 4)
rhandsontable(df1, selectCallback = TRUE,
readOnly = TRUE, rowHeaders = FALSE,
digits = 0) %>%
hot_table(highlightRow = TRUE, stretchH = "all") %>%
hot_cols(fixedRowsTop = 1, format = "00") %>%
hot_row(editable_rows, readOnly = FALSE)
)
What can I do about it? Do I have to install/add something in code to make it work smoothly?
This is an issue in the {reactable}
package as well, javascript being faster than R based renderers in that case but still painfully slow for sizeable tables. I think this is connected more to R and Shiny, although I have noticed that different packages can have remarkable speed differences when it comes to javascript stuff. For example {networkD3}
is massively faster and more lightweight than {plotly}
.