Reputation: 18625
Leaflet's markercluster plugin offers chunkProgress
callback function that provides information on the loading of data points, I would like to incorporate information from that function in Shiny's progress indicator displaying information on the number of loaded data points.
The app code draws on official examples made available by at Leaflet for R and Shiny's pages.
library(shiny)
library(leaflet)
r_colors <- rgb(t(col2rgb(colors()) / 255))
names(r_colors) <- colors()
noMarkers <- 200
ui <- fluidPage(leafletOutput("mymap"),
p(),
actionButton("recalc", "New points"))
server <- function(input, output, session) {
points <- eventReactive(input$recalc, {
cbind(rnorm(noMarkers) * 2 + 13, rnorm(noMarkers) + 48)
}, ignoreNULL = FALSE)
output$mymap <- renderLeaflet({
withProgress(message = 'Making plot', value = 0, {
# How can I replace noMarkers with dynamic values
# passed from the callback function
incProgress(1 / noMarkers, detail = paste("Doing point", noMarkers))
leaflet() %>%
addProviderTiles(providers$Stamen.TonerLite,
options = providerTileOptions(noWrap = TRUE)) %>%
addMarkers(data = points(),
clusterOptions = markerClusterOptions())
})
})
}
shinyApp(ui, server)
According to the information available through marker cluster pages:
chunkProgress
: Callback function that is called at the end of each chunkInterval. Typically used to implement a progress indicator, e.g. code in RealWorld 50k. Defaults tonull
. Arguments: Number of processed markers Total number of markers being added Elapsed time (in ms)
the chunkProgress
function should have all necessary information. In particular the structure of the progress bar would be call would be:
incProgress(Number of processed markers / Total number of markers,
detail = paste("Doing point", Number of processed markers))
How can I access those values and make them available for the incProgress
call and ensure that incProgress
is called repeatedly during the map plotting?
Leaflet offers bespoke plugins facilitating displaying of progress loading indicators. I'm only interested in a solution that would utilise Shiny's "native" mechanism of showing the progress bar as in the actual map I've other functions updating the progress bar.
Upvotes: 2
Views: 933