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

screenshooting a map with leafgl layer doesnt work #59

Open
trafficonese opened this issue Dec 14, 2020 · 4 comments
Open

screenshooting a map with leafgl layer doesnt work #59

trafficonese opened this issue Dec 14, 2020 · 4 comments

Comments

@trafficonese
Copy link
Collaborator

I dont think this is really a leafgl error and more a bug of the underlying JS-libraries (webshot, html2canvas, FileSaver?) but taking a screenshot of a map with leafgl data doesnt display the layer in the resulting image.

I tried several approaches to take a screenshot; mapview::mapshot, shinyscreenshot::screenshot and leaflet.extras2::addEasyprint.

Here's a shiny app which tries all those methods:

library(shiny)  
library(sf)
library(leaflet)
library(leafgl)
library(leaflet.extras2)
library(shinyscreenshot)
library(mapview)

storms = st_as_sf(atlStorms2005)
cols = heat.colors(nrow(storms))

ui <- fluidPage(
  actionButton("go", "Take a screenshot with `shinyscreenshot`"),
  actionButton("mapshot", "Take a screenshot with `mapview`"),
  leafletOutput("map"))

m <- leaflet()  %>% 
  addTiles() %>%
  addEasyprint(options = easyprintOptions(exportOnly = TRUE)) %>%
  addGlPolylines(data = storms, color = cols, popup = TRUE, opacity = 1)

server <- function(input, output, session) {
  output$map <- renderLeaflet({
    m
  })
  observeEvent(input$go, {
    screenshot()
  })
  observeEvent(input$mapshot, {
    mapshot(m, file = paste0(getwd(), "/map.png"))
  })
}
shinyApp(ui, server)

@tim-salabim
Copy link
Member

Did you also try https://github.com/rstudio/webshot2?

@trafficonese
Copy link
Collaborator Author

If we expose the option preserveDrawingBuffer and set it to TRUE the screenshot works with addEasyprint and screenshot, but somehow mapshot doesnt work.

No, I didnt try webshot2 yet.

@trafficonese
Copy link
Collaborator Author

trafficonese commented Dec 14, 2020

Indeed, webshot2 also works, even with preserveDrawingBuffer = FALSE.

@tim-salabim
Copy link
Member

That's good news I guess. I've been waiting for RStudio to push webshot2 to CRAN and rewrite mapshot accordingly which currently uses webshot. Until then, a fix using preseveDrawingBuffer seems like a good move. I'll have a look at changes needed for mapshot over the Christmas break. Thanks for bringing this up

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

2 participants