-
Notifications
You must be signed in to change notification settings - Fork 20
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
addWMS - authentication for title layer #54
Comments
Hey, |
Hi, |
Hello, Anyone had luck finding a workaround? I feel like I tried everything with no success :( |
I just pushed a new branch Can you install it with: and then test your Layer with an app like this: library(shiny)
library(leaflet)
library(leaflet.extras2)
LAYER <- "tiger:poi"
TOKEN <- paste0("user:strongpwd")
ui <- fluidPage(
leafletOutput("map", height = "500px")
)
server <- function(input, output, session) {
output$map <- renderLeaflet({
leaflet() %>%
addTiles(group = "base") %>%
addWMSHeader(baseUrl = "http://localhost:8080/geoserver/wms",
layers = LAYER,
options = leaflet::WMSTileOptions(transparent = TRUE, format = "image/png"),
header = list(
list("header" = "Authorization",
"value" = paste0("Basic ", base64enc::base64encode(charToRaw(TOKEN))) ),
list("header" = "content-type",
"value" = "text/plain")
)
) %>%
addLayersControl(baseGroups = "base", overlayGroups = LAYER)
})
}
shinyApp(ui, server) |
Hi, Thanks for the suggestion @trafficonese. Unfortunately it didn't work for me but I solved it in another way. Attaching the example below. I downloaded plugins from [ticinum-aerospace] via cmd and saved them i Shiny’s “www” folder. And then just re-wrote the code a bit. library(shiny)
library(leaflet)
library(htmltools)
library(httr)
library(Rcpp)
wms_headerPlugin <- htmlDependency(
name="leaflet-wms-header",
version="1.0.8",
src="www/leaflet-wms-header",
script="index.js"
)
ui=shinyUI(
bootstrapPage(theme="slate.min.css",
useShinyjs(),
add_busy_bar(color="white",height="8px"),
# Page size & html tags
tags$style(type="text/css","html, body {width:100%; height:95.5%}"),
# Leaflet map base map size
leafglOutput("Map",width="100%",height="100%"),
tags$head(
wms_headerPlugin # activating the plugin here
)
)
)
server=function(input, output, session) {
output$Map <- renderLeaflet({
leaflet() %>%
addTiles(layerId="Esri.WorldImagery") %>%
setView(lng=16,lat=62,zoom=5) %>%
htmlwidgets::onRender("
function(el, x) {
var map = this;
var wmsUrl = 'URL FOR WMS';
var wmsOptions = {
layers: 'LAYER',
format: 'image/png',
crs: L.CRS.EPSG3006,
transparent: true
};
var wmsHeaders = [
{ header: 'Authorization', value: 'Basic ' + btoa('USERNAME:PASSWORD') },
{ header: 'content-type', value: 'text/plain' }
];
var wmsLayer = L.TileLayer.wmsHeader(wmsUrl, wmsOptions, wmsHeaders);
map.addLayer(wmsLayer);
}
")
})
}
shinyApp(ui=ui,server=server) |
@kardemummabulle thanks for your input. |
@trafficonese thanks! It is indeed a real struggle, I can for instance see the WMS if I render it in the main output$Map but integrating it into observe({ }) part in more complex applications gives a battle right now. And I am not winning it yet :) Hope there is something that can be done at the package level. |
Hello, any luck integrating leaflet-wms-header with leaflet.extras2? :) |
Hi,
I am using a leaflet map in my RShiny application and would like to access an authenticated title layer. From the documentation I see that this feature is not currently supported. If there a way to add an authorisation header(bearer token authentication) to my request using the addWMS ? Or is there a workaround for the same ?
Many thanks in advance!
The text was updated successfully, but these errors were encountered: