我有一个大的数据集,但我提供了3个记录,使这个例子与可重复的 最小数据量.我能够在传单上显示所有3个网站一次,但我想 一次只显示一个记录.我的问题是,我怎么能在 map 上显示一个网站, 点击输入按钮的时间.例如,如何只显示site2而不显示 所有三个记录?我知道"switch ",但不知道如何实现它在这里. 我下面有一些代码和可复制的数据.谢谢你事先的任何建议.
Location geometry
* <chr> <POINT [°]>
1 site1 (-115.1682 44.3943)
2 site2 (-114.0403 44.6845)
3 site3 (-114.8841 44.1533)
library(shiny)
library(mapview)
library(writexl)
library(tidyverse)
library(leaflet)
locations <- c("site1", "site2", "site3")
ui <- fluidPage(
#titlePanel("Screwtraps and temp logger in Idaho"),
sidebarLayout(
sidebarPanel(
selectInput(inputId = "site",
label = "Select Site",
choices = locations)),
mainPanel(leafletOutput("map",width = "100%", height="87vh")
)
)
)
server <- function(input, output, session) {
session$onSessionEnded(function() {
stopApp()
})
output$map<-renderLeaflet({
#Select all sites
final <- mapview(site, col.regions='red', alpha=1)
final@map
#How can I render my map with only the selected site from the userInput dropdown?
})
}
shinyApp(ui, server)
Data is here:
site <- structure(list(Location = c("site1", "site2", "site3"), geometry = structure(list(
structure(c(-115.1682, 44.3943), class = c("XY", "POINT",
"sfg")), structure(c(-114.0403, 44.6845), class = c("XY",
"POINT", "sfg")), structure(c(-114.8841, 44.1533), class = c("XY",
"POINT", "sfg"))), n_empty = 0L, precision = 0, crs = structure(list(
input = "EPSG:4326", wkt = "GEOGCRS[\"WGS 84\",\n DATUM[\"World Geodetic System 1984\",\n ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n LENGTHUNIT[\"metre\",1]]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n CS[ellipsoidal,2],\n AXIS[\"geodetic latitude (Lat)\",north,\n ORDER[1],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n AXIS[\"geodetic longitude (Lon)\",east,\n ORDER[2],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n USAGE[\n SCOPE[\"Horizontal component of 3D system.\"],\n AREA[\"World.\"],\n BBOX[-90,-180,90,180]],\n ID[\"EPSG\",4326]]"), class = "crs"), bbox = structure(c(xmin = -115.1682,
ymin = 44.1533, xmax = -114.0403, ymax = 44.6845), class = "bbox"), class = c("sfc_POINT",
"sfc"))), row.names = c(NA, 3L), sf_column = "geometry", agr = structure(c(Location = NA_integer_), class = "factor", .Label = c("constant",
"aggregate", "identity")), class = c("sf", "tbl_df", "tbl", "data.frame"
))
site