Hi there,
I am using leaflet-easyPrint to print my leaflet map since it seems to be the easiest way to give the leaflet map a instant screenshot. (The mapshot() in mapview package seems not support leafletProxy object...)
My goal is to print all objects showing on the map, including the absolutePanel that made by shiny. I found once you put the absolutePanel into the leaflet htmlwiget, the JS library can successfully scrape the map.
Is there a way to hack this?
(Below is my repex for the example.)
Thank you in advance.
library(shiny)
library(leaflet)
library(htmlwidgets) # onRender()
jsfile <- "https://rawgit.com/rowanwins/leaflet-easyPrint/gh-pages/dist/bundle.js"
ui <- fluidPage(
tags$head(
tags$script(src = jsfile)
),
tags$div(
leafletOutput("mymap"),
absolutePanel(inputId="mypanel",
width = 280,
fixed = F,
draggable = T,
selectInput(inputId = "zoom",
label = "zoom level",
choices = 7:10,
selected = 7))
)
)
server <- function(input, output, session) {
output$mymap <- renderLeaflet({
leaflet() %>%
addTiles() %>%
onRender(
"function(el, x) {
L.easyPrint({
sizeModes: ['A4Landscape'],
filename: 'mymap',
exportOnly: true,
hideControlContainer: false
}).addTo(this); /* addTo(this)表示附加到這張地圖上*/
}"
)
})
changeZoom <- reactive({
as.numeric(input$zoom)
})
observe({
leafletProxy("mymap") %>%
setView(-93.65, 42.0285, zoom = changeZoom())
})
}
shinyApp(ui, server)