1

I am creating a Shiny App dashboard which involves plotting a map using Latitudes and Longitudes using Leaflet in one of the tabs. I need Leaflet for Zoom and the popup option. However, the map is not rendering in the app, it doesn't throw any error and shows a grey space where the map ideally should be. There were no such issues with the R console and it rendered the map perfectly.

I found a similar issue on the link below but it is not solving my issue. Shiny/Leaflet map not rendering.

I have also tried the workaround mentioned on this link below but it is breaking my other plots. https://github.com/rstudio/shiny/issues/650

ui <- dashboardPage(
  dashboardHeader(title = "Crimes Dashboard"),

  dashboardSidebar(
    sidebarMenu(
      menuItem("Tab1", tabName = "Tab1" , icon=icon("th")),
      menuItem("Tab2", tabName = "Tab2" , icon=icon("th")),
      menuItem("Tab3", tabName = "Tab3" , icon=icon("th")),
      menuItem("Tab4", tabName = "Tab4" , icon=icon("th"))
    )
  ),

  dashboardBody(
    tabItems(

      #Fourth Tab
      tabItem(tabName = "Tab4",
              h2("Tab4"),
              leafletOutput(outputId = "mymap")


      )

    )
  )
)


server <- function(input, output, session) {

  reactive_data2 <- reactive({
  crime <- crime[-which (is.na(crime$Location)),]
  })

  output$mymap <- renderLeaflet({

    reactive_data2() %>%
    mutate(popup = str_c(Date,
                         Block,
                         str_c("Location type:", `Location Description`,
                               sep = " "),
                         sep = "<br/>")) %>%
    leaflet() %>%
    addTiles() %>%
    addMarkers(clusterOptions = markerClusterOptions(),popup = ~popup) %>%
    frameWidget() 

  })
}

shinyApp(ui, server)
3
  • hi, could you provide a sample of the crime database you're using?
    – bretauv
    Commented Oct 26, 2019 at 12:56
  • you can download the data set from the link below data.cityofchicago.org/Public-Safety/Crimes-2001-to-present/… Commented Oct 26, 2019 at 19:18
  • that's a big file (at least 700Mb), could you just add a sample of that database in your code (with head for example)?
    – bretauv
    Commented Oct 27, 2019 at 12:48

1 Answer 1

1

I found a solution to this, removing the frameWidget() from the end solved the issue, thanks!

Not the answer you're looking for? Browse other questions tagged or ask your own question.