I am trying to develop a simple app with shiny using mapview. I need to display 2 different set of points (sf objects) but the map (mapview) is dsplayed without points.
---
title: "Registros de especies de vertebrados"
format:
html:
page-layout: custom
server: shiny
---
```{r}
#| panel: sidebar
selectInput("dataset", label = "Especie", choices = c("Especie 1", "Especie 2"))
```
```{r}
#| panel: fill
leafletOutput('plot1', height = "80vh")
```
```{r}
#| context: server
library(tidyverse)
library(rnaturalearth)
library(rnaturalearthhires)
library(sf)
library(mapview)
library(leaflet)
cr <- ne_countries(continent = "north america", scale = 10, returnclass = "sf") |>
dplyr::filter(iso_a3 == "CRI")
especie_01 = st_sample(cr, 100)
especie_02 = st_sample(cr, 100)
datasetInput <- reactive({
switch(input$dataset,
"Especie 01" = especie_01,
"Especie 02" = especie_02)
})
output$plot1 <- renderLeaflet({
dataset <- datasetInput()
m <- mapview(cr) + mapview(dataset)
m@map
})
```