Error: replacement has length zero

507 views
Skip to first unread message

Rose

unread,
May 7, 2015, 7:45:09 PM5/7/15
to shiny-...@googlegroups.com
I am trying to load a graphic generated after a somewhat lengthy calculation. Most of the time it works but sometimes I get an Error: Replacement length zero. The calculation is to generate a dataframe to conduct a 2d histogram. This never happens when I run the code on its own, only when it's presented in a Shiny app. Here's the code to trigger the function:

     output$clustersShow <- renderPlot({        
       if(input$clusterButton > 0) {
         clust.size <- input$clusterSlider
         numTraces <-30
         list_df <- makeClusters(numTraces)
         df1     <- list_df[[1]]
         drops     <- c("Trace")
         df1.clust <- df1[,!(names(df1) %in% drops)]
         df1C            <- bestCluster(df1.clust, clust.size, df1)
         df1C$clusterCat <- factor(df1C$Cluster)

         plot.cats       <- ggplot(df1C, aes(x=Noise, y = AvgC), colour=clusterCat) + geom_point( aes(color=clusterCat, size=4)) 
         plot.cats

       }
     })



It's makeClusters() that takes a while. I don't see this fitting into the isolate() or reactive() functions, but perhaps I am missing something. How can I get renderPlot to defer presenting the view until makeClusters() and subsequent functions return?

Joe Cheng

unread,
May 8, 2015, 12:15:02 AM5/8/15
to Rose, shiny-...@googlegroups.com
renderPlot does wait for makeClusters and the rest of the code to finish before returning.

I'd insert a browser() call right before (or maybe after) makeClusters() and walk through the code one line at a time to see where it fails. 

Sent from Outlook




--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/33376fe5-3416-4e97-b0cd-8bb4ffec6b23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages