Reputation: 173
Is there a way to improve the rendering speed / quality of mapping large datasets with a shiny app?
We were hoping to use shiny to create an app that showed the location of some our collected data, however we are finding that it may not be feasible. Our full dateset is close to 1 millions rows, and we are finding that the longer the table the harder it is to use the map. So far we have been using the leaflet package to map, and our dateset is imported in as a .RData file. Looking for advice on alternative libraries or coding practices I could imperilment to improve speed and quality.
Below is an example with some random sample data to show the issue we have been facing.
################################################################################################
################################################################################################
# Sec 1a. Needed Libaries & Input Files
# Libaries
library(shiny) # How we create the app.
library(shinycssloaders) # Adds spinner icon to loading outputs.
library(shinydashboard) # The layout used for the ui page.
library(leaflet) # Map making. Leaflet is more supported for shiny.
library(dplyr) # Used to filter data for plots.
FileIn <- data.frame(SiteID = 1:160000 , Longitude = rnorm(160000, mean=-105, sd=4), Latitude = rnorm(160000, mean=35, sd=4))
################################################################################################
################################################################################################
# Sec 2. The UI (HTML Page)
ui <- dashboardPage(
dashboardHeader(
title ="Sample point data"
), #enddashboardHeader
dashboardSidebar(
), #enddashboardSidebar
dashboardBody(
tabsetPanel(
tabPanel("Map", fluidRow(withSpinner(leafletOutput("mapA"))))
) #endtabsetPanel
) #enddashboardBody
) #end dashboardPage
################################################################################################
################################################################################################
# Sec 3. The Server (function)
server <- function(input, output, session) {
#### The Map ouput.
output$mapA <- renderLeaflet({
leaflet(data = FileIn) %>%
addTiles("Add Map Title Here") %>%
addProviderTiles("Esri.WorldImagery") %>%
addCircleMarkers(
lng = ~Longitude,
lat = ~Latitude,
radius = 1)
})
} #endServer
################################################################################################
################################################################################################
# Sec 4. Run the application.
shinyApp(ui = ui, server = server)
Upvotes: 0
Views: 635
Reputation: 2835
Do you mind using marker clustering? clusterOptions = markerClusterOptions()
library(shiny) # How we create the app.
library(shinycssloaders) # Adds spinner icon to loading outputs.
library(shinydashboard) # The layout used for the ui page.
library(leaflet) # Map making. Leaflet is more supported for shiny.
library(dplyr) # Used to filter data for plots.
FileIn <- data.frame(SiteID = 1:160000 , Longitude = rnorm(160000, mean=-105, sd=4), Latitude = rnorm(160000, mean=35, sd=4))
################################################################################################
################################################################################################
# Sec 2. The UI (HTML Page)
ui <- dashboardPage(
dashboardHeader(
title ="Sample point data"
), #enddashboardHeader
dashboardSidebar(
), #enddashboardSidebar
dashboardBody(
tabsetPanel(
tabPanel("Map", fluidRow(withSpinner(leafletOutput("mapA"))))
) #endtabsetPanel
) #enddashboardBody
) #end dashboardPage
################################################################################################
################################################################################################
# Sec 3. The Server (function)
server <- function(input, output, session) {
#### The Map ouput.
output$mapA <- renderLeaflet({
leaflet(data = FileIn) %>%
addTiles("Add Map Title Here") %>%
addProviderTiles("Esri.WorldImagery") %>%
addCircleMarkers(
lng = ~Longitude,
lat = ~Latitude,
radius = 1,
clusterOptions = markerClusterOptions())
})
} #endServer
################################################################################################
################################################################################################
# Sec 4. Run the application.
shinyApp(ui = ui, server = server)
Upvotes: 0