I have a question, is it possible to remove somehow blinking leaflet
map during refreshing?
I'm creating an application in Shiny
that handles a large dataset, filtered by sliderInput
(exactly the animation this widget offers) and then I process it and draw it. Although these calculations take less than a second, the map blinks while refreshing.
I noticed that with very simple and quick reductions it works smoothly.
Does anyone know an option how to freeze the "earlier" version of the map for the time of calculations, and then display the refreshed version in a smooth way or otherwise smooth the map refresh so that it is not annoying for the user?
Below is a simplified code that maps my application. I imitate the calculation with Sys.sleep(0.5)
.
I will be grateful for any help! Regards :)
library(shiny)
library(rgdal)
library(leaflet)
countries <- readOGR("https://rstudio.github.io/leaflet/json/countries.geojson")
ui <- basicPage(
fluidRow(column(10, offset = 1, uiOutput("slider"))),
fluidRow(leafletOutput("map"))
)
server <- shinyServer(function(input, output, session){
new_data <- reactive({
input$slider_id*runif(length(countries$gdp_md_est))
})
output$slider <- renderUI({
sliderInput(
width = '100%',
inputId = "slider_id",
label = "timeline:",
min = 0,
max = 10,
value = 0,
step = 1,
animate = TRUE
)
})
output$map <- renderLeaflet({
pal <- colorNumeric(c("#FF0000", "#FFFF00", "#00B050"), new_data())
Sys.sleep(0.5) # <- simulation of "longer" computations
leaflet(countries) %>%
addPolygons(
stroke = FALSE,
smoothFactor = 0.2,
fillOpacity = 1,
color = pal(new_data())
)
})
})
shinyApp(ui = ui, server = server)