Skip to main content
Bounty Ended with 50 reputation awarded by karpfen
added 45 characters in body
Source Link
Guz
  • 3.2k
  • 2
  • 19
  • 40

Using the RStudio IDE, your code worked fine in the Viewer Pane. However, it didn't worked using Firefox 52.0.1 browser.

Commenting the observer() function and adding addAwesomeMarkers () to the renderLeaflet({}) worked fine in Firefox 52.0.1 browser. I think Firefox 52.0.1 browser was right, because if you are using an observer function that mean it will draw the markers after the input$map_click action was done and never before that.

One property of the observer function is:

"An observer is like a reactive expression in that it can read reactive values and call reactive expressions ..." (from Shiny package documentation)"

Try the suggested code below from your reproducible example:

library(shiny)
library(sp)
library(leaflet)

ui <- bootstrapPage (leafletOutput("map", width = "80%", height = "800px"))

server <- function(input, output, session) {
  output$map <- renderLeaflet({
    print ("render tiles")
    b <- bbox (breweries91)
    leaflet (breweries91) %>%
      # addTiles () %>%
      addProviderTiles (providers$CartoDB.Positron) %>%
      addAwesomeMarkers () %>%
      fitBounds (b[1], b[2], b[3], b[4])
  })
  
  # observe ({
  #   print ("make markers")
  #   leafletProxy ("map", data = breweries91) %>%
  #     addAwesomeMarkers ()
  #   cl <- input$map_click
  #   if (!is.null (cl))
  #     print ("click")
  # })
}
shinyApp (ui, server)

Also, if you want to preserve the observe function but not to draw the markers at the begining, you can use it in this way:

observe ({
     print ("observe function called")
  #   leafletProxy ("map", data = breweries91) %>%
  #   addAwesomeMarkers ()
     cl <- input$map_click
     if (!is.null (cl))
       print ("click")
   })

Using the RStudio IDE, your code worked fine in the Viewer Pane. However, it didn't worked using Firefox 52.0.1 browser.

Commenting the observer() function and adding addAwesomeMarkers () to the renderLeaflet({}) worked fine in Firefox 52.0.1 browser. I think Firefox 52.0.1 browser was right, because if you are using an observer function that mean it will draw the markers after the input$map_click action was done and never before that.

One property of the observer function is:

"An observer is like a reactive expression in that it can read reactive values and call reactive expressions ... (from Shiny package documentation)"

Try the suggested code below from your reproducible example:

library(shiny)
library(sp)
library(leaflet)

ui <- bootstrapPage (leafletOutput("map", width = "80%", height = "800px"))

server <- function(input, output, session) {
  output$map <- renderLeaflet({
    print ("render tiles")
    b <- bbox (breweries91)
    leaflet (breweries91) %>%
      # addTiles () %>%
      addProviderTiles (providers$CartoDB.Positron) %>%
      addAwesomeMarkers () %>%
      fitBounds (b[1], b[2], b[3], b[4])
  })
  
  # observe ({
  #   print ("make markers")
  #   leafletProxy ("map", data = breweries91) %>%
  #     addAwesomeMarkers ()
  #   cl <- input$map_click
  #   if (!is.null (cl))
  #     print ("click")
  # })
}
shinyApp (ui, server)

Also, if you want to preserve the observe function you can use it in this way:

observe ({
     print ("observe function called")
  #   leafletProxy ("map", data = breweries91) %>%
  #   addAwesomeMarkers ()
     cl <- input$map_click
     if (!is.null (cl))
       print ("click")
   })

Using the RStudio IDE, your code worked fine in the Viewer Pane. However, it didn't worked using Firefox 52.0.1 browser.

Commenting the observer() function and adding addAwesomeMarkers () to the renderLeaflet({}) worked fine in Firefox 52.0.1 browser. I think Firefox 52.0.1 browser was right, because if you are using an observer function that mean it will draw the markers after the input$map_click action was done and never before that.

One property of the observer function is:

"An observer is like a reactive expression in that it can read reactive values and call reactive expressions ..." (from Shiny package documentation)

Try the suggested code below from your reproducible example:

library(shiny)
library(sp)
library(leaflet)

ui <- bootstrapPage (leafletOutput("map", width = "80%", height = "800px"))

server <- function(input, output, session) {
  output$map <- renderLeaflet({
    print ("render tiles")
    b <- bbox (breweries91)
    leaflet (breweries91) %>%
      # addTiles () %>%
      addProviderTiles (providers$CartoDB.Positron) %>%
      addAwesomeMarkers () %>%
      fitBounds (b[1], b[2], b[3], b[4])
  })
  
  # observe ({
  #   print ("make markers")
  #   leafletProxy ("map", data = breweries91) %>%
  #     addAwesomeMarkers ()
  #   cl <- input$map_click
  #   if (!is.null (cl))
  #     print ("click")
  # })
}
shinyApp (ui, server)

Also, if you want to preserve the observe function but not to draw the markers at the begining, you can use it in this way:

observe ({
     print ("observe function called")
  #   leafletProxy ("map", data = breweries91) %>%
  #   addAwesomeMarkers ()
     cl <- input$map_click
     if (!is.null (cl))
       print ("click")
   })
Source Link
Guz
  • 3.2k
  • 2
  • 19
  • 40

Using the RStudio IDE, your code worked fine in the Viewer Pane. However, it didn't worked using Firefox 52.0.1 browser.

Commenting the observer() function and adding addAwesomeMarkers () to the renderLeaflet({}) worked fine in Firefox 52.0.1 browser. I think Firefox 52.0.1 browser was right, because if you are using an observer function that mean it will draw the markers after the input$map_click action was done and never before that.

One property of the observer function is:

"An observer is like a reactive expression in that it can read reactive values and call reactive expressions ... (from Shiny package documentation)"

Try the suggested code below from your reproducible example:

library(shiny)
library(sp)
library(leaflet)

ui <- bootstrapPage (leafletOutput("map", width = "80%", height = "800px"))

server <- function(input, output, session) {
  output$map <- renderLeaflet({
    print ("render tiles")
    b <- bbox (breweries91)
    leaflet (breweries91) %>%
      # addTiles () %>%
      addProviderTiles (providers$CartoDB.Positron) %>%
      addAwesomeMarkers () %>%
      fitBounds (b[1], b[2], b[3], b[4])
  })
  
  # observe ({
  #   print ("make markers")
  #   leafletProxy ("map", data = breweries91) %>%
  #     addAwesomeMarkers ()
  #   cl <- input$map_click
  #   if (!is.null (cl))
  #     print ("click")
  # })
}
shinyApp (ui, server)

Also, if you want to preserve the observe function you can use it in this way:

observe ({
     print ("observe function called")
  #   leafletProxy ("map", data = breweries91) %>%
  #   addAwesomeMarkers ()
     cl <- input$map_click
     if (!is.null (cl))
       print ("click")
   })