如何解决如何从R Shiny&Leaflet的过滤器中排除NULL值?
有没有办法从R Shiny和传单地图中的过滤器中排除NULL数据值,同时仍在地图上显示该点?
在此示例中,我需要支持以下用例:1)按总体大小过滤,但可以选择2)查看在“总体”中包含NULL值的网站。
以下示例说明了我要完成的工作(在这种情况下,我不确定如何构建具有NULL值的数据框)。
# ################################################################################################
# ################################################################################################
# # Sec 1a. Needed Libraries& Input Files
library(shiny)
library(shinydashboard)
library(shinyWidgets) # more options to work with shiny,like inputs
library(leaflet)
library(dplyr)
##The Data
Map_DF <- data.frame("Point_ID" = c("A","B","C","D"),"Latitude" = c(38.05,39.08,40.05,41.08),"Longitude" = c(-107.00,-107.05,-108.00,-108.50),"PointUse" = c("farm","house","well","house"),"Population" = c(1,2,NULL,4)) #Input data here would have NULL value.
################################################################################################
################################################################################################
#UI
ui <- dashboardPage(
dashboardHeader(),dashboardSidebar(
materialSwitch(inputId = "Null_Values",label = "Include Empty Values (Null)?",value = FALSE,status = "primary"),sliderInput(inputId = "PopInput",label = "Population",min = 1,max = 4,value = c(1,4))
),dashboardBody(
fluidRow(leafletOutput(outputId = 'mapA'))
)
)
################################################################################################
################################################################################################
server <- function(input,output,session) {
observeEvent(input$Null_Values {
if (input$Null_Values == TRUE) {
#allow to view site on map
}
})
## The Filter
filterdf <- reactive({
Map_DF %>%
filter(
(Population >= input$PopInput[1]),(Population <= input$PopInput[2])
)
})
## Base Map Creation
output$mapA <- renderLeaflet({
leaflet() %>%
addProviderTiles(
providers$Esri.DeLorme,options = providerTileOptions(
updateWhenZooming = FALSE,updateWhenIdle = TRUE)
) %>%
setView(lng = -107.50,lat = 39.00,zoom = 6)
})
## Update Map with Filter Selection
observe({
leafletProxy("mapA",session) %>%
clearMarkers() %>%
addCircleMarkers(
data = filterdf(),radius = 10,color = "red",lat = ~Latitude,lng = ~Longitude,popupOptions(autoPan = FALSE),popup = ~paste("Population: ",filterdf()$Population))
})
}
################################################################################################
################################################################################################
shinyApp(ui = ui,server = server)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。