I try to build an shiny app. And it actually it works. Basically I have a dataset (20'000 rows) which i change with sliders and Groupcheckboxes and then plot to a map using ggmap. But it is really slow (a change takes about 10 to 20 seconds). Is there any possibility to make the app running faster. Does it have to do with the subset function? Or is it because of the ggmap plot? I added my generic server code.
would be grateful for every kind of help.
shinyServer(
function(input, output) {
data_subset <- reactive({
subset(pladata_no_na_loc, (pladata_no_na_loc$FUEL_FACTOR == input$fueltype[1] |
pladata_no_na_loc$FUEL_FACTOR == input$fueltype[2] |
pladata_no_na_loc$FUEL_FACTOR == input$fueltype[3] |
pladata_no_na_loc$FUEL_FACTOR == input$fueltype[4] |
pladata_no_na_loc$FUEL_FACTOR == input$fueltype[5] |
pladata_no_na_loc$FUEL_FACTOR == input$fueltype[6] |
pladata_no_na_loc$FUEL_FACTOR == input$fueltype[7]) &
((pladata_no_na_loc$MW >= input$slider_mw[1]) & (pladata_no_na_loc$MW <
input$slider_mw[2] ) ) &
((pladata_no_na_loc$MIN_YEAR >= input$slider_year[1]) & (pladata_no_na_loc$MIN_YEAR <
input$slider_year[2] ) ),
select = c("enipedia_latitude", "enipedia_longitude", "MW_FACTOR", "MW", "FUEL_FACTOR"),
drop = FALSE)
})
output$map <- renderPlot({
mapPoints <- ggmap(map) +
geom_point(data = data_subset(), drop = FALSE ,
aes(x = enipedia_longitude, y = enipedia_latitude, size = MW, color = FUEL_FACTOR),
alpha = .5)
print(mapPoints)
}, height = 900, width = 1000)
}
)