我想将一个数值滑块输入与散点图和传单地图链接起来,这样当我从sliderinput中选择输入范围时,地图上的标记会被滤除,散点图会根据选择而淡出。仅将滑块输入链接到地图,而不将散点图链接。我希望能够链接这三个组件;地图,散点图和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)