r - 如何在闪亮的应用程序中将反应参数同步到光栅砖
问题描述
我正在尝试使用 16 层的光栅砖创建一个闪亮的应用程序。我似乎无法梳理出服务器中的反应参数。似乎无论我尝试什么,我都无法让 selectInput 与我对栅格砖名称的反应输入同步。为什么我的闪亮应用程序没有拾取单独的图层?selectInput 的值与栅格砖的名称相匹配。我尝试了不同的方法让反应函数获取层的名称。
更新:我发现这个旧帖子显示必须为每一层指定数据路径。有人可以更详细地解释一下为每一层指定数据路径吗?
library(leafem)
library(terra)
library(raster)
library(sp)
library(here)
library(stars)
library(lubridate)
library(tidyverse)
library(rasterVis)
library(shiny)
library(leaflet)
library(patchwork)
library(plotly)
library(rgdal)
library(terra)
library(rasterVis)
library(animation)
library(htmlwidgets)
url <- "http://thredds.cdip.ucsd.edu//thredds/fileServer/cdip/model/MOP_grids/CA_0.01_forecast.nc"
options(timeout = 10000)
data <- download.file(url, "/Users/mycomp/Desktop/wave_data.nc")
data_set <- "wave_data.nc"
waves <- rast(data_set, sub = "waveHs")
ROU <- ext(-121.0062, -118.7438, 33.10625, 34.90625)
wave_crop <- crop(waves, ROU)
remove_txt <- gsub("waveHs_waveTime.", "", names(wave_crop)) %>%
as.numeric() %>%
as_datetime()
names(wave_crop) <- c(remove_txt)
names(wave_crop)
raz_temp <- rast(xmin = -121.0062,
xmax = -118.7438,
ymin = 33.10625,
ymax = 34.90625,
resolution = c(0.001, 0.001))
brick_resample <- resample(wave_crop, raz_temp)
names(brick_resample)
wave_pal <- colorRampPalette(c("blue", "cyan", "yellow", "red"))
library(shiny)
ui <- fluidPage(
titlePanel("Wave Model"),
leafletOutput("brick_resample", height = 500),
selectInput("names", "Select Date Range",
names(brick_resample))
)
server <- function(input, output, session){
#Reactive
slid <- reactive({
raster::brick(brick_resample$layer$datapath)
#brick_resample$names
#names(brick_resample)
#brick_resample[names]
})
#Map
output$brick_resample <- renderLeaflet({
leaflet(options = leafletOptions(minZoom = 8.5)) %>%
addPolygons(data = islands, color = 'black', opacity = 1, weight = 2, fill = F)%>%
addPolygons(data = ca, color = 'black', opacity = 1, weight = 2, fill = F)%>%
addProviderTiles("Esri.OceanBasemap") %>%
addRasterImage(x = slid(), colors = wave_pal(5)) %>%
setView(lng = -119.200336, lat = 34.14, zoom = 9) %>%
setMaxBounds(lng1 = -121.0,
lat1 = 33.1125,
lng2 = -118.75,
lat2 = 34.9)
})
}
shinyApp(ui = ui, server = server)
解决方案
推荐阅读
- c++ - 在 C++ 中从空格分隔的文本文件中读取数字
- java - Spring Security 重定向到 https
- python - 如何转换超声图像以模拟 CT 图像?
- asynchronous - Rust 异步方法回调/关闭
- javascript - 在我的 view.py 中的请求中没有“数据”属性
- html - 如何使用网格将文本与输入对齐
- reactjs - 如何模拟useEffect?
- r - 仅选择以字母开头的字符串的前两位数字,否则不执行任何操作
- unit-testing - 将 PCOV 与 --coverage 一起使用时,代码接收测试失败
- reactjs - TypeError:无法读取 React js 中未定义的属性“有效负载”