Open SymbolixAU opened 5 years ago
Still noticing this is slower, especially when setting to FALSE vs clearing the layer
library(shiny)
library(shinydashboard)
library(mapdeck)
ui <- dashboardPage(
dashboardHeader()
, dashboardSidebar(
actionButton(inputId = "roads", label = "roads")
)
, dashboardBody(
mapdeckOutput(outputId = "map")
)
)
library(sfheaders)
df <- sfheaders::sf_to_df( roads )
df <- rbind( df, df, df, df)
nrow( df )
# 231028
server <- function(input, output) {
## initialise a map
output$map <- renderMapdeck({
mapdeck( location = c(144.9, -37), zoom = 5 )
})
## use an observer to add and remove layers
observeEvent({input$roads},{
mapdeck_update(map_id = "map") %>%
add_scatterplot(
data = df
, lon = "x"
, lat = "y"
, layer_id = "myRoads"
, fill_colour = "RIGHT_LOC"
, visible = ( input$roads %% 2 == 1 )
)
})
}
shinyApp(ui, server)
server <- function(input, output) {
## initialise a map
output$map <- renderMapdeck({
mapdeck( location = c(144.9, -37), zoom = 5 )
})
## use an observer to add and remove layers
observeEvent({input$roads},{
if( input$roads %% 2 == 1 ) {
mapdeck_update(map_id = "map") %>%
add_scatterplot(
data = df
, lon = "x"
, lat = "y"
, layer_id = "myRoads"
, fill_colour = "RIGHT_LOC"
)
} else {
mapdeck_update(map_id = "map") %>%
clear_scatterplot(layer_id = "myRoads")
})
}
shinyApp(ui, server)
https://deck.gl/#/documentation/developer-guide/performance-optimization?section=minimize-data-changes
clear_layer()
/add_layer()
each time.