Skip to main content
deleted 33 characters in body; edited tags
Source Link
Jan
  • 6.4k
  • 4
  • 15
  • 26

I have some code below and reproducible data. Thanks in advance for any advice.

I have some code below and reproducible data. Thanks in advance for any advice.

I have some code below and reproducible data.

added 3 characters in body
Source Link
marc_s
  • 747.8k
  • 180
  • 1.4k
  • 1.5k

I have a large dataset but I am providing 3 records to make this example reproducible with the minimum minimum amount of data. I am able to show on leaflet all the 3 sites at once but I would like to show show one record at a time as well. My question is, how can I manage to show on the map one site at the the time when the input dropdown is clicked. 

For example, how can I show site2 only instead of showing all all the 3 records? I am aware of 'switch' but don't know how to implement it here. I

I have some code below and reproducible data. Thanks beforehandin advance for any advice.

I have a large dataset but I am providing 3 records to make this example reproducible with the minimum amount of data. I am able to show on leaflet all the 3 sites at once but I would like to show one record at a time as well. My question is, how can I manage to show on the map one site at the time when the input dropdown is clicked. For example, how can I show site2 only instead of showing all the 3 records? I am aware of 'switch' but don't know how to implement it here. I have some code below and reproducible data. Thanks beforehand for any advice.

I have a large dataset but I am providing 3 records to make this example reproducible with the minimum amount of data. I am able to show on leaflet all the 3 sites at once but I would like to show one record at a time as well. My question is, how can I manage to show on the map one site at the time when the input dropdown is clicked. 

For example, how can I show site2 only instead of showing all the 3 records? I am aware of 'switch' but don't know how to implement it here.

I have some code below and reproducible data. Thanks in advance for any advice.

Source Link
Salvador
  • 1.5k
  • 1
  • 14
  • 22

How to visualize single points in shiny app mapview leaflet

I have a large dataset but I am providing 3 records to make this example reproducible with the minimum amount of data. I am able to show on leaflet all the 3 sites at once but I would like to show one record at a time as well. My question is, how can I manage to show on the map one site at the time when the input dropdown is clicked. For example, how can I show site2 only instead of showing all the 3 records? I am aware of 'switch' but don't know how to implement it here. I have some code below and reproducible data. Thanks beforehand for any advice.

  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

enter image description here