Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R shiny server + leaflet Memory leak #1952

Closed
ElmienSpoelstra opened this issue Feb 23, 2018 · 2 comments
Closed

R shiny server + leaflet Memory leak #1952

ElmienSpoelstra opened this issue Feb 23, 2018 · 2 comments
Assignees
Milestone

Comments

@ElmienSpoelstra
Copy link

ElmienSpoelstra commented Feb 23, 2018

Background

I have to create a prototype map based dashboard for a project. I decided on R shiny, as it had the best data management for my data, and easy to use. I use Leaflet in combination with Rshiny. After creating the map, it gets updated at certain intervals and recreates the map with new data (kind off batch real time). The data will be quite a lot, but is still manageable on a leaflet application.

Code:

library(shinydashboard)
library(leaflet)

ui <- fluidPage(
  dashboardBody(
    box(width = NULL, solidHeader = TRUE,
                 leafletOutput("busmap", height = 900)
    )
  )
)

server <- function(input, output) {

liveish_data <- reactive({
    invalidateLater(6000)
    lat <- runif(3000, min=51, max=53.5)
    lon <- runif(3000, min=4, max=8)
    DF_Actueel <- data.frame(lat,lon)
    print("refreshed")
    DF_Actueel
  })

  output$busmap = renderLeaflet({
    DF_Actueel <- liveish_data()
    map <- leaflet(options=list())%>%
      addProviderTiles(providers$OpenStreetMap.HOT) %>%
      addMarkers(data = DF_Actueel)

    map
  })
}

shinyApp(ui, server)

Issue

I was checking my taks manager while running the app. My problem is that when this app is run, RStudio uses some memory (approximately 350MB on my pc), and every time it updates, the memory usage of Rshiny increases by 20MB.

> object.size(map)
148000 byte

This means after a few minutes, Rstudio runs out of memory. I have given it more memory... but that just means it runs out later.

Own Research

I have looked at similar questions:
https://stackoverflow.com/questions/30818373/shiny-r-reactivevalues-memory-leak -- Unanswered
#1551 -- Used the Observe() function
#1591 -- I used the options(shiny.reactlog=TRUE) and check the output. I have only one map object
#1151 -- Used Plotly instead of leaflet and was not solved, even though it was closed.
There was some more along the same topics and same unanswered questions.

Specifications

Windows 10
24GB RAM
64-bit operating system
Intel(R) Core i7-6700HQ CPU @ 2.6GHz
R version 3.4.3 (2017-11-30)
leaflet 1.1.0
shinydashboard 0.6.1

I hope someone can help. Thank you :)

@jcheng5 jcheng5 added this to the 1.1 milestone Apr 10, 2018
@tmastny tmastny self-assigned this Jun 14, 2018
@tmastny
Copy link
Contributor

tmastny commented Jul 10, 2018

I wasn't able to replicate this issue. I profiled your app with profvis and was able to see memory being reclaimed with garbage collection.

Are you still able to replicate this problem? How long does it take for RStudio to crash? Also could you try upgrading to the latest version of Shiny and R?

@ElmienSpoelstra
Copy link
Author

I just copied this code into my R studio as a new script ran it and it still happens. The memory drops by 10MB and then rises by 20 again. So it seems to collect some garbage but it is not enough.

However, I did solve the problem of updating the map by using leaflet proxy instead. This work well even for large data sets.

@jcheng5 jcheng5 closed this as completed Sep 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants