You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm new to this space so apologies if this is user error.
Suppose we want to display mapview::franconia in Shiny and get the ID of the polygon that a user clicks.
Using leaflet, one could pass layerId to the addPolygons function. For example,
ui<-shiny::bootstrapPage(
shiny::tags$style(type="text/css", "html, body {width:100%;height:100%}"),
leaflet::leafletOutput("map", width="100%", height="100%")
)
server<-function(input, output, session) {
output$map<-leaflet::renderLeaflet({
mapview::franconia|>leaflet::leaflet() |>leaflet::addProviderTiles("CartoDB.Positron") |>leaflet::addPolygons(layerId=mapview::franconia$NUTS_ID)
})
shiny::observeEvent(input$map_shape_click, {
# Looking for the `$id` element to be "DE268" or similar
print(input$map_shape_click)
})
}
shiny::shinyApp(ui, server)
According to the docs on ?mapview, we should be able to pass this argument to addPolygons. That is,
ui<-shiny::bootstrapPage(
shiny::tags$style(type="text/css", "html, body {width:100%;height:100%}"),
leaflet::leafletOutput("map", width="100%", height="100%")
)
server<-function(input, output, session) {
output$map<-leaflet::renderLeaflet({
mv<-mapview::mapview(mapview::franconia, layerId=mapview::franconia$NUTS_ID)
mv@map
})
shiny::observeEvent(input$map_shape_click, {
# Looking for the `$id` element to be "DE268" or similar
print(input$map_shape_click)
})
}
shiny::shinyApp(ui, server)
However,
Passing no extra arguments, the click information returns id as NULL
Passing the layerId results in
Error in validateScalarName: Invalid argument 'name' (must be a non-empty character string and contain no '/' or '')
One workaround would be use the latitude and longitude information returned but this is not ideal.
Edit: Another workaround would be to use mapview::mapviewOptions(fgb = FALSE), is it possible to get the same functionality with fbg?
The text was updated successfully, but these errors were encountered:
I'm new to this space so apologies if this is user error.
Suppose we want to display
mapview::franconia
in Shiny and get the ID of the polygon that a user clicks.Using
leaflet
, one could passlayerId
to theaddPolygons
function. For example,According to the docs on
?mapview
, we should be able to pass this argument toaddPolygons
. That is,However,
id
asNULL
layerId
results inOne workaround would be use the latitude and longitude information returned but this is not ideal.
Edit: Another workaround would be to use
mapview::mapviewOptions(fgb = FALSE)
, is it possible to get the same functionality with fbg?The text was updated successfully, but these errors were encountered: