leaflet.extras
leaflet.extras copied to clipboard
addDrawToolbar in modules throws TypeError: t is undefined
By using the addDrawToolbar
in shiny modules on different tabs, the following Javascript error comes up in the console.
TypeError: t is undefined leaflet.js:5:10033
To trigger the error, start the app, go to Tab "mod2" and back to "mod1" and click on the map. Every interaction with the map will cause another console error.
shinyApp
## libs & data ###################################
library(shiny)
library(sf)
library(leaflet)
library(leaflet.extras)
drawtoolbar = TRUE
sfdata <- sf::st_as_sf(breweries91, coords="coordinates")
## modules ###################################
mod1_ui <- function(id, label, value) {
ns <- NS(id)
tabPanel(label, value = value, leafletOutput(ns("map"))
)
}
mod1_server <- function(input, output, session, parent_session, navid) {
output$map <- renderLeaflet({
req(parent_session$input$navbarid == navid)
p <- leaflet() %>%
addTiles()
if (drawtoolbar) {
p <- p %>% addDrawToolbar(position="topright",
targetGroup = "Sel")
}
p
})
}
## ui ###################################
ui <- navbarPage(id = "navbarid", title = 'DEMO', selected = 1,
mod1_ui("mod1", "mod1", 1),
mod1_ui("mod2", "mod2", 2)
)
## server ###################################
server <- function(input, output, session) {
callModule(mod1_server, "mod1", parent_session = session, navid = 1)
callModule(mod1_server, "mod2", parent_session = session, navid = 2)
}
## Run App ###################################
shinyApp(ui, server)
Interestingly, the error disappears when the following line in renderLeaflet
is removed:
req(parent_session$input$navbarid == navid)