R Shiny / Leaflet 中的时间序列叶绿素

问题描述 投票:0回答:1

如何使用传单在 RShiny 中随时间推移制作分区统计图的动画?我想根据它们的数值在 Shiny 中随时间对等值区域的颜色进行动画处理。

下面是我尝试过的方法,但是在点击滑块上的播放按钮(或更改滑块上的日期)后,分区图不会改变颜色。我希望分区图随着年份作为输入而改变颜色。

这里是我想要复制的示例的链接,但我似乎无法让它在我这边工作:https://towardsdatascience.com/eye-having-animated-maps-in-r-a-simple-简介-3559d8c33be1

这是闪亮的应用程序代码:

library(shiny)

library(shiny)

ui <- fluidPage(
  titlePanel("Chamonix Snow Development"),
  
  sidebarPanel(width = 2,
               
               sliderInput("dateSel", "Date",
                           min = min(snow_total_year_abs$year),
                           max = max(snow_total_year_abs$year),
                           value = min(snow_total_year_abs$year),
                           step = 1,
                           timeFormat = "%d %b %y",
                           animate = animationOptions(interval = 200, loop = FALSE)
               )
               
  ),
  
  mainPanel(width = 10,
            
            leafletOutput("map", width = "70%", height = "750px")
            
  )
)


server <- function(input, output, session) {
  
  output$map = renderLeaflet({
    leaflet(stations %>% filter(year==min(stations$year))) %>%
      addTiles() %>% addPolygons( data = vcrop,
                                  weight=2, opacity = 1,
                                  color = stations$color,
                                  fillOpacity = 0.5) 
    
  })
  
  observe({
    leafletProxy({
      leafletProxy("map", data = stations %>% filter(year==input$dateSel)) 
    })
    
  })
  
}

shinyApp(ui, server)

Here is the code getting the coordinate data into polygon form:

test = ac_ml_join %>% filter(Name=="Admont" | Name =="Fieberbrunn")

stations = st_as_sf(test,coords = c("Longitude","Latitude"))

#create voronoi/thiessen polygons
v <- stations %>% 
  st_union() %>%
  st_voronoi() %>%
  st_collection_extract()

box <- st_bbox( stations ) %>% st_as_sfc()
vparts = st_collection_extract(v)
vcrop = st_crop(vparts, box)

leaflet(stations) %>% 
  addTiles() %>% 
  #addCircleMarkers( data = stations ) %>%
  addPolygons( data = vcrop,fillColor = stations$color,
               weight=2, opacity = 1,
               color = stations$color,
               fillOpacity = 0.5) 
'Test' dataset:
year max.snow Name    `3yr_roll_avg` snow.vis color     Longitude Latitude
1971    4.35  Absdorf          2.93     100   royalblue      16.0     48.4
1972    2.28  Absdorf          3.07     105.  royalblue      16.0     48.4
1973    2.58  Absdorf          1.62      55.2 red            16.0     48.4
1974    0     Absdorf          1.16      39.6 darkred        16.0     48.4
1975    0.903 Absdorf          0.508     17.3 darkred        16.0     48.4
1976    0.621 Absdorf          3.31     113.  royalblue      16.0     48.4
1977    8.42  Absdorf          5.44     186.  purple         16.0     48.4
1978    7.29  Absdorf          8.04     274.  purple         16.0     48.4
1979    8.42  Absdorf          7.41     253.  purple         16.0     48.4
1980    6.52  Absdorf          6.02     205.  purple         16.0     48.4
1971     20.9 Admont           8.77     100  royalblue      14.5     47.6
1972      3.6 Admont          26.4      301. purple         14.5     47.6
1973     54.7 Admont          29.7      339. purple         14.5     47.6
1974     30.9 Admont          42.8      488. darkred        14.5     47.6
1975     42.9 Admont          39.6      451. purple         14.5     47.6
1976     45.0 Admont          43.2      492. purple         14.5     47.6
1977     41.7 Admont          42.5      485. red            14.5     47.6
1978     40.9 Admont          37.3      426. purple         14.5     47.6
1979     29.4 Admont          40.7      464. purple         14.5     47.6
1980     51.8 Admont          56.8      647. purple         14.5     47.6
r shiny leaflet gis choropleth
1个回答
0
投票

你最终解决这个问题了吗?

ac_ml_join
从哪里来?

© www.soinside.com 2019 - 2024. All rights reserved.