Linking sliderInput, leaflet map and scatter plot

I want to link a numeric sliderinput with scatter plot and leaflet map such that when i select a range of input from the sliderinput, markers on the map are filtered out and the scatter plot fades out depending on the selection.The code below only links the sliderinputs to the map but not the scatter plot. I want to be able to link the 3 components; map, scatter plot and sliderInput.

library(shiny
library(leaflet)
library(rgdal)
library(ggplot2)
geo<-readOGR(dsn = path.expand("./www/map"),layer = "geo")
geo1<-geo@data
ui<-fluidPage(
fluidRow(
          column(4,
                 sliderInput(inputId = "os1",
                             label = "Offsite Sanitation(Sewarage):",
                             min = min(geo1$Offst_S,na.rm =T),
                             max = max(geo1$Offst_S,na.rm =T),
                             value = c(min(geo1$Offst_S,na.rm =T),
                                       max(geo1$Offst_S,na.rm =T))
                 ),
                 sliderInput(inputId = "os2",
                             label = "Onsite Sanitation:",
                             min = min(geo1$Onst_Sn,na.rm =T),
                             max = max(geo1$Onst_Sn,na.rm =T),
                             value = c(min(geo1$Onst_Sn,na.rm =T),
                                       max(geo1$Onst_Sn,na.rm =T))
                 ),
                 sliderInput(inputId = "wt",
                             label = "Waste Water Treated(Safely Managed):",
                             min = min(geo1$WW_trtd,na.rm =T),
                             max = max(geo1$WW_trtd,na.rm =T),
                             value = c(min(geo1$WW_trtd,na.rm =T),
                                       max(geo1$WW_trtd,na.rm =T))
                 ),

                 sliderInput(inputId = "fce",
                             label = "Feacal Sludge Contained Not Emptied(Safely Managed):",
                             min = min(geo1$FS_cn__,na.rm =T),
                             max = max(geo1$FS_cn__,na.rm =T),
                             value = c(min(geo1$FS_cn__,na.rm =T),
                                       max(geo1$FS_cn__,na.rm =T))
                 ),

                 sliderInput(inputId = "ft",
                             label = "Feacal Sludge Treated(Safely Managed):",
                             min = min(geo1$FS_trtd,na.rm =T),
                             max = max(geo1$FS_trtd,na.rm =T),
                             value = c(min(geo1$FS_trtd,na.rm =T),
                                       max(geo1$FS_trtd,na.rm =T))
                 )
          )

),
column(4,
                 leafletOutput("leaf")  

          ),
column(4,plotOutput("plot")

)
        )

server<-function(input,output,session){
#reactive function for slider input
san<-reactive({
    subset(geo1,geo1$Offst_S>=input$os1[1]&
             geo1$Offst_S<=input$os1[2]&
             geo1$Onst_Sn>=input$os2[1]&
             geo1$Onst_Sn<=input$os2[2]&
             geo1$WW_trtd>=input$wt[1]&
             geo1$WW_trtd<=input$wt[2]&
             geo1$FS_cn__>=input$fce[1]&
             geo1$FS_cn__<=input$fce[2]&
             geo1$FS_trtd>=input$ft[1]&
             geo1$FS_trtd<=input$ft[2]




    )
  })

#base map for interactive mapping
  output$leaf<-renderLeaflet({


    leaflet(geo1)%>%

      #addTiles()%>%

      addProviderTiles("Esri.NatGeoWorldMap")%>% 
      addAwesomeMarkers(
        data=geo1,
        label = ~ City

      )
  }

  )

  #observe function for slider input numeric options
  observe({


    leafletProxy("leaf2",data=san()) %>%

      #Initializing the map
      clearMarkers() %>%
      clearControls() %>%
      #clearShapes()%>%
      addAwesomeMarkers(
        #fillColor=~pal(input$os1),
        label = ~City

      ) 

  })




  #plot explorer 
  output$plot<-renderPlot({
    #xvar<-geo1[,c(input$x)]
    #yvar<-geo1[,c(input$y)]

         data_plot<-subset(geo1, geo1$Offst_S>=input$os1[1]&
             geo1$Offst_S<=input$os1[2]&
               geo1$Onst_Sn>=input$os2[1]&
               geo1$Onst_Sn<=input$os2[2]
             )






    # build graph with ggplot syntax
      ggplot(data_plot, aes(x =geo1$Offst_S , y =geo1$Onst_Sn  )) +
      geom_point()

     #x<-geo1[,c(input$x,input$y)]
    # x<-san()
    #  plot(x,col = "#75AADB", pch = 19,main=paste0(input$y,"  vs ",input$x))

  })
}

shinyApp(ui,server)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.