0

When I change the input in the selectInput selector to show various groupings on the map, the full dataset shows up and doesn't change when the input changes.

ui <- dashboardPage(
  dashboardHeader(title = "Businesses in South Bend"),
  dashboardSidebar(),
  dashboardBody(
  fluidPage(
    titlePanel("Business by Type"),
    sidebarLayout(
        sidebarPanel(
            selectInput(inputId = 'Classifi_1',
                        label = 'Choose Business Type',
                        choices = unique(df_tidy$Classifi_1),
                        selected = 'TAXI VEHICLE')
        ),

        mainPanel(
          tabsetPanel(
            tabPanel(title = 'Map',
                     leafletOutput(outputId = 'mymap'))
          )
        )
    )
)))

server <- function(input, output) {

    output$mymap <- renderLeaflet({
      leaflet()%>%
        addTiles()%>%
        addMarkers(data = df_tidy, popup = df_tidy$Business_N)
        
        
    })
}

I tried adding a selected part of the selectInput and it still showed all the data points and still nothing changed when input changed.

corinbog
  • 11
  • 1

1 Answers1

0

I don't see that you've used the inputID of "Classifi_1" to filter your data on server side. You will want to create a reactive for your filtered data set. Try something like this:

df_tidy_r <- reactive({df_tidy %>% filter(Classifi_1 == input$Classifi_1) })

And then in output$mymap be sure to use data = df_tidy_r()

output$mymap <- renderLeaflet({
      leaflet()%>%
        addTiles()%>%
        addMarkers(data = df_tidy_r(), popup = df_tidy_r()$Business_N)

And use ObserveEvent to trigger refreshing output$mymap when you change input$Classifi_1.

ObserveEvent(input$Classifi_1,{
output$mymap <- renderLeaflet({
      leaflet()%>%
        addTiles()%>%
        addMarkers(data = df_tidy_r(), popup = df_tidy_r()$Business_N)  
})

stomper
  • 1,252
  • 1
  • 7
  • 12