r - 在 R 中向传单地图添加交互式时间滑块
问题描述
我正在尝试使用传单创建美国的交互式彩色编码地图。我的目标是在移动时间滑块时让每个状态的填充发生变化。
我在 ui 中显示了地图和时间滑块,但它们没有链接。
我有 2 个数据集。一种原始数据显示州名称、日期和分类/填充(map_plot)。第二个是我从底格里斯河中提取的大型空间多边形,并与原始数据 (us_merged) 连接。
这是我到目前为止的代码。
library(shiny)
library(leaflet)
library(dplyr)
# Define UI for application that shows a map
ui <- fluidPage(
# App title
# Input: select date range
sliderInput("Date",
"Date:",
min = today(),
max = max(map_plot$date),
value= today(),
timeFormat="%Y-%m-%d"),
# Main panel for Output
mainPanel(
# Output: map
leafletOutput("map_leaflet")
)
)
# Define server commands to draw map with data
server <- function(input, output) {
# Reactive expression to generate dataframe for selected date and metric
d <- reactive({
day <- us_merged$date
#show_metric <- us_merged$changing_status
d <- us_merged %>%
subset(date == day) #%>%
#dplyr::select(INTPTLAT,INTPTLON,show_metric) %>%
# rename(selected_metric = show_metric)
})
# Note: the last pipeline element renames the metric column back to a neutral name
#create the map
output$map_leaflet <- renderLeaflet({
leaflet(d()) %>%
addTiles() %>%
setView(-98.483330, 38.712046, zoom = 3.25) %>%
addPolygons(
fillColor = ~pal(changing_status),
fillOpacity = 0.5,
weight = 2,
color = 'white',
smoothFactor = 0.2,
popup = popup)
})
}
# Run app
shinyApp(ui, server)
解决方案
推荐阅读
- vb.net - vb.net 如何获取文本文件的文件名?
- docker - 启动我的 dockerized laravel 应用程序时出现服务器错误(500)
- swift - xCode Like-button 不会在表格单元格中创建 (EXC_BAD_ACCESS (code=2, address=0x7fff86e8d750))
- javascript - 开玩笑在服务中模拟 mongodb 记录
- javascript - 带有子组件的 Blazor 页面:如何从行 @onclick 方法按钮传递当前 HTML 表格行索引或 Vairable
- python - Using WriteToBigQuery FILE_LOADS in a streaming pipeline just creates a LOT of temporary tables (python SDK)
- ios - 如何检查是否在 iOS 上使用 Flutter 安装了特定应用程序?
- java - 如何从java文件更改可绘制源?
- vim - VimScript:语法高亮插件不高亮
- go - 在 golang 中修改映射值 - 有和没有指针 - 意外行为