Skip to content
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

addDrawToolbar in modules throws TypeError: t is undefined #179

Open
trafficonese opened this issue Dec 19, 2019 · 1 comment
Open

addDrawToolbar in modules throws TypeError: t is undefined #179

trafficonese opened this issue Dec 19, 2019 · 1 comment
Labels

Comments

@trafficonese
Copy link
Owner

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)

@trafficonese
Copy link
Owner Author

related rstudio/leaflet#657

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant