2

I am having problem rendering an interactive map using R shiny and leaflet. I am able to render the plot for the first time but when I change certain inputs (input$inputTime in this case), the map (output$main_map) greys out.

UI.r

library(shiny)
library(leaflet)
ui <- fluidPage(
  includeCSS("style.css"),
  titlePanel("Welcome to the app!"),

  sidebarLayout(
    sidebarPanel(
      radioButtons("inputCrimeRate", 
                   "Crime Rate",
                   choices = c("All", "High", "Medium", "Low"),
                   selected = "All"),
      radioButtons("inputTime", 
                   "Time of the day",
                   choices = c("All_day", "AM", "PM"),
                   selected = "All_day",inline = TRUE),
      selectInput("inputCrimeType",
                  "Crime Type",
                  choices = c("Theft", "Assault", "DUI"))
      #actionButton(inputId = "go",label="update")
      ),

    mainPanel(
      renderText(output$test),
      leafletOutput("main_map"),
      "test_014",
      br()
    )
  )
)

server.r

library(shiny)
library(ggmap)
library(ggplot2)
library(leaflet)
server <- function(input,output)
{
  geocodeQueryCheck()
  #load("app2/data03.Rda")

  #main map
  output$main_map <- renderLeaflet({ 

                                  time <- input$inputTime

                                  if(time == "All_day")
                                    {data05 <- data04}
                                  else if (time == "AM")
                                  {data05 <- data04[data04$Occured.Time2 == "AM",]}
                                  else if (time == "PM")
                                  {data05 <- data04[data04$Occured.Time2 == "PM",]}



                                  leaflet(data05) %>% 
                                  addTiles() %>% 
                                  setView(-84.5092756,39.1268475,zoom=12) %>% 
                                  addCircles(popup=data04$Offense, weight=2,radius=10)

                            }
                          )


}
YASH
  • 21
  • 3
  • 4
    Please look at [this post](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to build a reproducible example – HubertL Dec 27 '16 at 00:05

0 Answers0