I'm trying to incorporate the easyPrint plugin into my shiny leaflet app. What I want is something that looks like the demo, but in shiny.
I have tried to mimic the examples, but have been unsuccessful.
Here's my code for my R code so far:
library(shiny)
library(shinydashboard)
library(shinyjs)
library(htmlwidgets)
library(htmltools)
library(leaflet)
library(leaflet.extras)
library(sp)
shinyApp(
ui = fluidPage(
leafletOutput("map", height = 750)
),
server = function(input, output) {
registerPlugin <- function(map, plugin) {
map$dependencies <- c(map$dependencies, list(plugin))
map
}
easyPrintPlugin <- htmlDependency("leaflet-easyprint", "2.1.8",
src = c(href = "https://github.com/rowanwins/leaflet-easyPrint/blob/gh-pages/dist/"),
script = "index.js")
# Map
output$map <- renderLeaflet({
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
registerPlugin(easyPrintPlugin) %>%
onRender("function(el, x) {
L.easyPrint({
position: 'topleft',
sizeModes: ['A4Portrait', 'A4Landscape']
}).addTo(map);}")
})
}
)
However, nothing is happening. It's literally a white screen. If I remove the onRender part, the leaflet acts normal.
Unfortunately, I'm relatively new to Shiny, leaflet, .js, and github, so I'm struggling to identify which aspect is causing the problem.
See Question&Answers more detail:os