【发布时间】:2019-04-03 20:58:51
【问题描述】:
在示例数据框DF 中,我有以下列。
gender <- c("Male", "Female","Female", "Male")
Location <- c("AB", "BC", "CD", "DE")
hasTV <- c("Yes","Yes","No","No")
Latitude <- c(49.82380908513249,59.478568831926395,59.478568831926395,49.82380908513249)
Longitude <- c(-10.8544921875,-10.8544921875,2.021484375,2.021484375)
DF <- data.frame(gender,Location,hasTV,Latitude,Longitude)
在 UI 下,我使用 radiobuttons 从 hasTV 中选择选项,checkboxGroupInput 选择 Gender 并使用 selectInput 创建位置下拉列表。我已经在fluidRow 中实现了这一点,如下所示。
sex <- unique(DF$gender)
loc <- unique(DF$Location)
hastv <- unique(DF$hasTV)
radioButtons("radio_hastv",label = "Has TV", choices = hastv, selected = "Yes")
checkboxGroupInput("checkbox_gender", label = "Gender", choices = sex, selected = sex)
selectInput("Location", label = "Location", choices=loc, selected = "AB")
leafletOutput("mymap", height = 415)
在服务器函数中,我有多个基于所选输入的反应式表达式。这就是我实现表达式的方式。
filtered_gender <- reactive({
DF[DF$gender == input$checkbox_gender,]
})
filtered_hastv <- reactive({
DF[DF$hasTV == input$radio_hastv,]
})
filtered_loc <- reactive({
DF[DF$Location == input$loc,]
})
我已经渲染了传单地图。但是,我希望在以某种方式选择所有这三个输入时更改我的地图。例如如果一个人选择,gender=Male,location=DE 并且 hasTV=No,则在地图上绘制具有正确 gps 的适当地图。
到目前为止,我只能使用一种反应式表达式来更新传单地图,如下所示。
observe(leafletProxy("mymap", data = filtered_loc()) %>%
clearMarkers()%>%
addMarkers(radius =3)%>%
label = ~htmlEscape(DF$hasTV)
)
如何合并其他反应式表达式,以便地图相应地更改。谢谢。
【问题讨论】:
标签: r shiny shinydashboard reactive r-leaflet