shiny and mapview in a quarto document

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

})
```

Hi Manolo,
seems to be a simple typo. In your selectInput the choices are "Especie 1" & "Especie 2", but in the reactive datasetInput your switch refers to "Especie 01" & "Especie 02". Aligning those renders everything as expected for me.

Best
Tim

Thank you very much Tim.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.