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?