Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert row get slower in shiny WITH an observeEvent on the input$[name of the table] #98

Closed
dominiqueemmanuel opened this issue Aug 9, 2016 · 7 comments

Comments

@dominiqueemmanuel
Copy link

Hi,

Thanks for this R package !!

When I use an rhandsontable in a shiny application with an event observer, if I insert rows in the table ([right click] on a row then [insert row below]) the time spent to insert the row get slower and slower (after 10 insertions, the time is long, and avec 20 insertions the time is longer, etc...).

NB : if I remove the observeEvent lines, this is not happening anymore.

Do you have an idea how to solve this problem ?

Best regards,
Dom

Here is an example :

library(shiny)
library(rhandsontable)
ui<-fluidPage(
  rHandsontableOutput("aa")
)

server = function(input, output) {
  verbatim_rv<-reactiveValues()
  n<-100
  verbatim_rv$xx<-data.frame(c1="a"%>%paste0(seq(n)),c2="a"%>%paste0(seq(n)),c3="a"%>%paste0(seq(n)),c4="a"%>%paste0(seq(n)),c5="a"%>%paste0(seq(n)))

  ## When removing these lines, the problems doesn't happen anymore
  observeEvent(input$aa,{
    verbatim_rv$xx <<- hot_to_r(input$aa)
  })

  output$aa <- renderRHandsontable({
    choices<-letters[1:10]
    rule_table<-verbatim_rv$xx 
    rhandsontable(rule_table) %>% hot_context_menu() %>%
      hot_col(col = c("c1"), type = "autocomplete",source = choices,strict = FALSE) %>%
      hot_col(col = c("c2"), type = "autocomplete",source = choices,strict = FALSE) %>%
      hot_col(col = c("c3"), type = "autocomplete",source = choices,strict = FALSE) %>%
      hot_col(col = c("c4"), type = "autocomplete",source = choices,strict = FALSE) %>%
      hot_col(col = c("c5"), type = "autocomplete",source = choices,strict = FALSE) %>%
      hot_table(contextMenu=TRUE)
  })
}
app<-shinyApp(ui, server)
runApp(app,launch.browser=TRUE)

Here is my session informations :


> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252   
[3] LC_MONETARY=French_France.1252 LC_NUMERIC=C                  
[5] LC_TIME=French_France.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rhandsontable_0.3.2 shiny_0.13.2       

loaded via a namespace (and not attached):
 [1] htmlwidgets_0.7 magrittr_1.5    R6_2.1.2        tools_3.3.1    
 [5] htmltools_0.3.5 yaml_2.1.13     Rcpp_0.12.6     jsonlite_1.0   
 [9] digest_0.6.10   xtable_1.8-2    httpuv_1.3.3    mime_0.5     
@jrowen
Copy link
Owner

jrowen commented Aug 10, 2016

I haven't heard of this issue before. If you can debug further and provide more detail around which method is causing the issue, I can take a quick look.

@dominiqueemmanuel
Copy link
Author

dominiqueemmanuel commented Aug 10, 2016

Yes, it seems to be a mysterious issue.

I'm pretty sure the issue is caused by the incrementation of the reactive value (i.e. in my example observeEvent(input$aa, { verbatim_rv$xx <<- hot_to_r(input$aa) })).

In practice I can manage to reduce the gravity of the issue by preventing unnecessary incrementations, but the problem is still happening...

@dominiqueemmanuel
Copy link
Author

dominiqueemmanuel commented Aug 10, 2016

For information, I have tried to trace each part of the code (with a system.timecall and print) : every call of the code seems not to take more time while the number of inserted rows increases.

However, the increasing time seems to come from javascript...

@jrowen
Copy link
Owner

jrowen commented Aug 10, 2016

Does the issue appear to like with the rhandsontable, handsontable or
htlmwidgets functionality?

On Wed, Aug 10, 2016 at 8:37 AM dominiqueemmanuel notifications@github.com
wrote:

For information, I have tried to trace each part of the code (with a
system.timecall and print) : every call of the code seems not to spend
more time while the number of inserted rows increases.

However, the increasing time seems come from javascript...


You are receiving this because you commented.

Reply to this email directly, view it on GitHub
#98 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABdYrtP5eyXKfat0aolvXVVlswvhDxk-ks5qedQDgaJpZM4JgUpm
.

@dominiqueemmanuel
Copy link
Author

I don't think the issue comes (directly) from handsontable, because only inserting rows does not cause the issue (the issue only begins to appears if I add the line observeEvent(input$aa, { verbatim_rv$xx <<- hot_to_r(input$aa) }) ).

I don't know exactly where the time is used.

However, if I trace with options(shiny.trace = TRUE), I can see that the time used is between
SEND {"errors":[],"values":{"aa":{"x":{"data":[{"c1":"a1","c2":"a1","c3":"a1","c4":........
and
RECV {"method":"update","data":{"aa":{"data":[["a1","a1",......

@govertbuijs
Copy link

We're running into a similar problem using 0.3.3.
To debug : add the following code to rhandsontable.js, starting at line 84 (top of x.afterChange):

if (x.foo === undefined) {
  x.foo = new Date();
}
console.log(x.foo);

The list increases on every edit when there's an eventObserver on the table.
Somehow additional data objects keep getting created in JS, but i can't find who holds them.

@jrowen
Copy link
Owner

jrowen commented Sep 1, 2016

Thanks for filing an issue. This looks to be an issue with handsontable (or our implementation thereof).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants