0

I am new to Leaflet and Shiny and would like to create two reactive functions from two columns in my shapefile frame(map1). I would want the application to redraw polygons based on the input made in these functions (input of an Area and an Integer value).

Please any help to fix the below code to derive the desired output would be appreciated.

ui <- fluidPage(
    titlePanel(p("Learn Shiny", style = "color:#3474A7")),
    sidebarLayout(
        sidebarPanel(

            checkboxGroupInput(inputId = "AreaFinder",
                               label = "Select Areas(s):",
                               choices = unique(map1$Areas),
                               selected = "Christchurch"),
            
            checkboxGroupInput(inputId = "NumberID",
                               label = "Select number:",
                               choices = unique(map1$No),
                               selected = 0)
            ),
     
        mainPanel(
            leafletOutput(outputId = "Dorset_map")
        )
    )
)


# server()

# server()

server <- function(input, output) {
    
    data_input <- reactive({
        map1 %>%
            filter (map1$No == input$AreaFinder) 
        AND
        filter(map1$Areas == input$NumberID)
    })
    
    output$Dorset_map <- renderLeaflet({
        leaflet() %>%
            addTiles() %>%
            addPolygons(data = map1,
                        fillColor = pal(data_input()$Area),
                        weight = 1,
                        smoothFactor = 0.5,
                        color = "white",
                        fillOpacity = 0.8,
                        highlight = highlightOptions(
                            weight = 5,
                            color = "#666",
                            dashArray = "",
                            fillOpacity = 0.7,
                            bringToFront = TRUE))
        
    })
}


# shinyApp()
shinyApp(ui = ui, server = server)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.