1

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)

   }
  )
Al Lelopath
  • 6,448
  • 13
  • 82
  • 139
Milan
  • 11
  • 2
  • 1) Its best if you tag your question with 'shiny' too. 2) I think you structured your app in a way that it re-evaluates the entire dataset each time you change something. 3) Try not to use subset if you can, use [] where possible http://stackoverflow.com/questions/9860090/in-r-why-is-better-than-subset – Pork Chop Nov 04 '14 at 16:10
  • I think you can use dplyr to solve this problem, it can really make your computations faster. – Neeraj Komuravalli Mar 19 '17 at 18:38

1 Answers1

0

I'm not totally sure, but here is my assumption. Its that you are evulating the dataset / subset on each call. Try adding a submit button to make sure all the commands happen at once. Every time you move the slider it rerenders the code, thus rerunning the script. So if you move it 3 times, it is basically loading it again. I've found it could be since its not give a lot of space on your computer. For some reason , some of my apps do much better on the server than my laptop.

patchus
  • 97
  • 4